1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsPrintSettingsImpl.h"
40 #include "nsReadableUtils.h"
41 #include "nsIPrintSession.h"
43 #define DEFAULT_MARGIN_WIDTH 0.5
45 NS_IMPL_ISUPPORTS1(nsPrintSettings
, nsIPrintSettings
)
47 /** ---------------------------------------------------
48 * See documentation in nsPrintSettingsImpl.h
51 nsPrintSettings::nsPrintSettings() :
53 mPrintRange(kRangeAllPages
),
57 mPrintBGColors(PR_FALSE
),
58 mPrintBGImages(PR_FALSE
),
59 mPrintFrameTypeUsage(kUseInternalDefault
),
60 mPrintFrameType(kFramesAsIs
),
61 mHowToEnableFrameUI(kFrameEnableNone
),
62 mIsCancelled(PR_FALSE
),
63 mPrintSilent(PR_FALSE
),
64 mPrintPreview(PR_FALSE
),
65 mShrinkToFit(PR_TRUE
),
66 mShowPrintProgress(PR_TRUE
),
69 mPaperSizeType(kPaperSizeDefined
),
72 mPaperSizeUnit(kPaperSizeInches
),
73 mPrintReversed(PR_FALSE
),
74 mPrintInColor(PR_TRUE
),
75 mOrientation(kPortraitOrientation
),
76 mDownloadFonts(PR_FALSE
),
78 mPrintToFile(PR_FALSE
),
79 mOutputFormat(kOutputFormatNative
),
80 mIsInitedFromPrinter(PR_FALSE
),
81 mIsInitedFromPrefs(PR_FALSE
)
84 /* member initializers and constructor code */
85 nscoord marginWidth
= NS_INCHES_TO_TWIPS(DEFAULT_MARGIN_WIDTH
);
86 mMargin
.SizeTo(marginWidth
, marginWidth
, marginWidth
, marginWidth
);
87 mEdge
.SizeTo(0, 0, 0, 0);
88 mUnwriteableMargin
.SizeTo(0,0,0,0);
90 mPrintOptions
= kPrintOddPages
| kPrintEvenPages
;
92 mHeaderStrs
[0].AssignLiteral("&T");
93 mHeaderStrs
[2].AssignLiteral("&U");
95 mFooterStrs
[0].AssignLiteral("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
96 mFooterStrs
[2].AssignLiteral("&D");
100 /** ---------------------------------------------------
101 * See documentation in nsPrintSettingsImpl.h
102 * @update 6/21/00 dwc
104 nsPrintSettings::nsPrintSettings(const nsPrintSettings
& aPS
)
109 /** ---------------------------------------------------
110 * See documentation in nsPrintSettingsImpl.h
111 * @update 6/21/00 dwc
113 nsPrintSettings::~nsPrintSettings()
117 /* [noscript] attribute nsIPrintSession printSession; */
118 NS_IMETHODIMP
nsPrintSettings::GetPrintSession(nsIPrintSession
**aPrintSession
)
120 NS_ENSURE_ARG_POINTER(aPrintSession
);
121 *aPrintSession
= nsnull
;
123 nsCOMPtr
<nsIPrintSession
> session
= do_QueryReferent(mSession
);
125 return NS_ERROR_NOT_INITIALIZED
;
126 *aPrintSession
= session
;
127 NS_ADDREF(*aPrintSession
);
130 NS_IMETHODIMP
nsPrintSettings::SetPrintSession(nsIPrintSession
*aPrintSession
)
132 // Clearing it by passing NULL is not allowed. That's why we
133 // use a weak ref so that it doesn't have to be cleared.
134 NS_ENSURE_ARG(aPrintSession
);
136 mSession
= do_GetWeakReference(aPrintSession
);
138 // This may happen if the implementation of this object does
139 // not support weak references - programmer error.
140 NS_ERROR("Could not get a weak reference from aPrintSession");
141 return NS_ERROR_FAILURE
;
146 /* attribute long startPageRange; */
147 NS_IMETHODIMP
nsPrintSettings::GetStartPageRange(PRInt32
*aStartPageRange
)
149 //NS_ENSURE_ARG_POINTER(aStartPageRange);
150 *aStartPageRange
= mStartPageNum
;
153 NS_IMETHODIMP
nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange
)
155 mStartPageNum
= aStartPageRange
;
159 /* attribute long endPageRange; */
160 NS_IMETHODIMP
nsPrintSettings::GetEndPageRange(PRInt32
*aEndPageRange
)
162 //NS_ENSURE_ARG_POINTER(aEndPageRange);
163 *aEndPageRange
= mEndPageNum
;
166 NS_IMETHODIMP
nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange
)
168 mEndPageNum
= aEndPageRange
;
172 /* attribute boolean printReversed; */
173 NS_IMETHODIMP
nsPrintSettings::GetPrintReversed(PRBool
*aPrintReversed
)
175 //NS_ENSURE_ARG_POINTER(aPrintReversed);
176 *aPrintReversed
= mPrintReversed
;
179 NS_IMETHODIMP
nsPrintSettings::SetPrintReversed(PRBool aPrintReversed
)
181 mPrintReversed
= aPrintReversed
;
185 /* attribute boolean printInColor; */
186 NS_IMETHODIMP
nsPrintSettings::GetPrintInColor(PRBool
*aPrintInColor
)
188 //NS_ENSURE_ARG_POINTER(aPrintInColor);
189 *aPrintInColor
= mPrintInColor
;
192 NS_IMETHODIMP
nsPrintSettings::SetPrintInColor(PRBool aPrintInColor
)
194 mPrintInColor
= aPrintInColor
;
198 /* attribute short orientation; */
199 NS_IMETHODIMP
nsPrintSettings::GetOrientation(PRInt32
*aOrientation
)
201 NS_ENSURE_ARG_POINTER(aOrientation
);
202 *aOrientation
= mOrientation
;
205 NS_IMETHODIMP
nsPrintSettings::SetOrientation(PRInt32 aOrientation
)
207 mOrientation
= aOrientation
;
211 /* attribute wstring colorspace; */
212 NS_IMETHODIMP
nsPrintSettings::GetColorspace(PRUnichar
* *aColorspace
)
214 NS_ENSURE_ARG_POINTER(aColorspace
);
215 if (!mColorspace
.IsEmpty()) {
216 *aColorspace
= ToNewUnicode(mColorspace
);
218 *aColorspace
= nsnull
;
222 NS_IMETHODIMP
nsPrintSettings::SetColorspace(const PRUnichar
* aColorspace
)
225 mColorspace
= aColorspace
;
227 mColorspace
.SetLength(0);
232 /* attribute wstring resolutionname; */
233 NS_IMETHODIMP
nsPrintSettings::GetResolutionName(PRUnichar
* *aResolutionName
)
235 NS_ENSURE_ARG_POINTER(aResolutionName
);
236 if (!mResolutionName
.IsEmpty()) {
237 *aResolutionName
= ToNewUnicode(mResolutionName
);
239 *aResolutionName
= nsnull
;
243 NS_IMETHODIMP
nsPrintSettings::SetResolutionName(const PRUnichar
* aResolutionName
)
245 if (aResolutionName
) {
246 mResolutionName
= aResolutionName
;
248 mResolutionName
.SetLength(0);
253 /* attribute boolean downloadFonts; */
254 NS_IMETHODIMP
nsPrintSettings::GetDownloadFonts(PRBool
*aDownloadFonts
)
256 //NS_ENSURE_ARG_POINTER(aDownloadFonts);
257 *aDownloadFonts
= mDownloadFonts
;
260 NS_IMETHODIMP
nsPrintSettings::SetDownloadFonts(PRBool aDownloadFonts
)
262 mDownloadFonts
= aDownloadFonts
;
266 /* attribute wstring printer; */
267 NS_IMETHODIMP
nsPrintSettings::GetPrinterName(PRUnichar
* *aPrinter
)
269 NS_ENSURE_ARG_POINTER(aPrinter
);
271 *aPrinter
= ToNewUnicode(mPrinter
);
272 NS_ENSURE_TRUE(*aPrinter
, NS_ERROR_OUT_OF_MEMORY
);
277 NS_IMETHODIMP
nsPrintSettings::SetPrinterName(const PRUnichar
* aPrinter
)
279 if (!aPrinter
|| !mPrinter
.Equals(aPrinter
)) {
280 mIsInitedFromPrinter
= PR_FALSE
;
281 mIsInitedFromPrefs
= PR_FALSE
;
284 mPrinter
.Assign(aPrinter
);
288 /* attribute long numCopies; */
289 NS_IMETHODIMP
nsPrintSettings::GetNumCopies(PRInt32
*aNumCopies
)
291 NS_ENSURE_ARG_POINTER(aNumCopies
);
292 *aNumCopies
= mNumCopies
;
295 NS_IMETHODIMP
nsPrintSettings::SetNumCopies(PRInt32 aNumCopies
)
297 mNumCopies
= aNumCopies
;
301 /* attribute wstring printCommand; */
302 NS_IMETHODIMP
nsPrintSettings::GetPrintCommand(PRUnichar
* *aPrintCommand
)
304 //NS_ENSURE_ARG_POINTER(aPrintCommand);
305 *aPrintCommand
= ToNewUnicode(mPrintCommand
);
308 NS_IMETHODIMP
nsPrintSettings::SetPrintCommand(const PRUnichar
* aPrintCommand
)
311 mPrintCommand
= aPrintCommand
;
313 mPrintCommand
.SetLength(0);
318 /* attribute boolean printToFile; */
319 NS_IMETHODIMP
nsPrintSettings::GetPrintToFile(PRBool
*aPrintToFile
)
321 //NS_ENSURE_ARG_POINTER(aPrintToFile);
322 *aPrintToFile
= mPrintToFile
;
325 NS_IMETHODIMP
nsPrintSettings::SetPrintToFile(PRBool aPrintToFile
)
327 mPrintToFile
= aPrintToFile
;
331 /* attribute wstring toFileName; */
332 NS_IMETHODIMP
nsPrintSettings::GetToFileName(PRUnichar
* *aToFileName
)
334 //NS_ENSURE_ARG_POINTER(aToFileName);
335 *aToFileName
= ToNewUnicode(mToFileName
);
338 NS_IMETHODIMP
nsPrintSettings::SetToFileName(const PRUnichar
* aToFileName
)
341 mToFileName
= aToFileName
;
343 mToFileName
.SetLength(0);
348 /* attribute short outputFormat; */
349 NS_IMETHODIMP
nsPrintSettings::GetOutputFormat(PRInt16
*aOutputFormat
)
351 NS_ENSURE_ARG_POINTER(aOutputFormat
);
352 *aOutputFormat
= mOutputFormat
;
355 NS_IMETHODIMP
nsPrintSettings::SetOutputFormat(PRInt16 aOutputFormat
)
357 mOutputFormat
= aOutputFormat
;
361 /* attribute long printPageDelay; */
362 NS_IMETHODIMP
nsPrintSettings::GetPrintPageDelay(PRInt32
*aPrintPageDelay
)
364 *aPrintPageDelay
= mPrintPageDelay
;
367 NS_IMETHODIMP
nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay
)
369 mPrintPageDelay
= aPrintPageDelay
;
373 /* attribute boolean isInitializedFromPrinter; */
374 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrinter(PRBool
*aIsInitializedFromPrinter
)
376 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter
);
377 *aIsInitializedFromPrinter
= (PRBool
)mIsInitedFromPrinter
;
380 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrinter(PRBool aIsInitializedFromPrinter
)
382 mIsInitedFromPrinter
= (PRPackedBool
)aIsInitializedFromPrinter
;
386 /* attribute boolean isInitializedFromPrefs; */
387 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrefs(PRBool
*aInitializedFromPrefs
)
389 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs
);
390 *aInitializedFromPrefs
= (PRBool
)mIsInitedFromPrefs
;
393 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrefs(PRBool aInitializedFromPrefs
)
395 mIsInitedFromPrefs
= (PRPackedBool
)aInitializedFromPrefs
;
399 /* attribute double marginTop; */
400 NS_IMETHODIMP
nsPrintSettings::GetMarginTop(double *aMarginTop
)
402 NS_ENSURE_ARG_POINTER(aMarginTop
);
403 *aMarginTop
= NS_TWIPS_TO_INCHES(mMargin
.top
);
406 NS_IMETHODIMP
nsPrintSettings::SetMarginTop(double aMarginTop
)
408 mMargin
.top
= NS_INCHES_TO_TWIPS(float(aMarginTop
));
412 /* attribute double marginLeft; */
413 NS_IMETHODIMP
nsPrintSettings::GetMarginLeft(double *aMarginLeft
)
415 NS_ENSURE_ARG_POINTER(aMarginLeft
);
416 *aMarginLeft
= NS_TWIPS_TO_INCHES(mMargin
.left
);
419 NS_IMETHODIMP
nsPrintSettings::SetMarginLeft(double aMarginLeft
)
421 mMargin
.left
= NS_INCHES_TO_TWIPS(float(aMarginLeft
));
425 /* attribute double marginBottom; */
426 NS_IMETHODIMP
nsPrintSettings::GetMarginBottom(double *aMarginBottom
)
428 NS_ENSURE_ARG_POINTER(aMarginBottom
);
429 *aMarginBottom
= NS_TWIPS_TO_INCHES(mMargin
.bottom
);
432 NS_IMETHODIMP
nsPrintSettings::SetMarginBottom(double aMarginBottom
)
434 mMargin
.bottom
= NS_INCHES_TO_TWIPS(float(aMarginBottom
));
438 /* attribute double marginRight; */
439 NS_IMETHODIMP
nsPrintSettings::GetMarginRight(double *aMarginRight
)
441 NS_ENSURE_ARG_POINTER(aMarginRight
);
442 *aMarginRight
= NS_TWIPS_TO_INCHES(mMargin
.right
);
445 NS_IMETHODIMP
nsPrintSettings::SetMarginRight(double aMarginRight
)
447 mMargin
.right
= NS_INCHES_TO_TWIPS(float(aMarginRight
));
451 /* attribute double edgeTop; */
452 NS_IMETHODIMP
nsPrintSettings::GetEdgeTop(double *aEdgeTop
)
454 NS_ENSURE_ARG_POINTER(aEdgeTop
);
455 *aEdgeTop
= NS_TWIPS_TO_INCHES(mEdge
.top
);
458 NS_IMETHODIMP
nsPrintSettings::SetEdgeTop(double aEdgeTop
)
460 mEdge
.top
= NS_INCHES_TO_TWIPS(float(aEdgeTop
));
464 /* attribute double edgeLeft; */
465 NS_IMETHODIMP
nsPrintSettings::GetEdgeLeft(double *aEdgeLeft
)
467 NS_ENSURE_ARG_POINTER(aEdgeLeft
);
468 *aEdgeLeft
= NS_TWIPS_TO_INCHES(mEdge
.left
);
471 NS_IMETHODIMP
nsPrintSettings::SetEdgeLeft(double aEdgeLeft
)
473 mEdge
.left
= NS_INCHES_TO_TWIPS(float(aEdgeLeft
));
477 /* attribute double edgeBottom; */
478 NS_IMETHODIMP
nsPrintSettings::GetEdgeBottom(double *aEdgeBottom
)
480 NS_ENSURE_ARG_POINTER(aEdgeBottom
);
481 *aEdgeBottom
= NS_TWIPS_TO_INCHES(mEdge
.bottom
);
484 NS_IMETHODIMP
nsPrintSettings::SetEdgeBottom(double aEdgeBottom
)
486 mEdge
.bottom
= NS_INCHES_TO_TWIPS(float(aEdgeBottom
));
490 /* attribute double edgeRight; */
491 NS_IMETHODIMP
nsPrintSettings::GetEdgeRight(double *aEdgeRight
)
493 NS_ENSURE_ARG_POINTER(aEdgeRight
);
494 *aEdgeRight
= NS_TWIPS_TO_INCHES(mEdge
.right
);
497 NS_IMETHODIMP
nsPrintSettings::SetEdgeRight(double aEdgeRight
)
499 mEdge
.right
= NS_INCHES_TO_TWIPS(float(aEdgeRight
));
503 /* attribute double unwriteableMarginTop; */
504 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginTop(double *aUnwriteableMarginTop
)
506 NS_ENSURE_ARG_POINTER(aUnwriteableMarginTop
);
507 *aUnwriteableMarginTop
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.top
);
510 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginTop(double aUnwriteableMarginTop
)
512 if (aUnwriteableMarginTop
>= 0.0) {
513 mUnwriteableMargin
.top
= NS_INCHES_TO_TWIPS(aUnwriteableMarginTop
);
518 /* attribute double unwriteableMarginLeft; */
519 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginLeft(double *aUnwriteableMarginLeft
)
521 NS_ENSURE_ARG_POINTER(aUnwriteableMarginLeft
);
522 *aUnwriteableMarginLeft
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.left
);
525 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft
)
527 if (aUnwriteableMarginLeft
>= 0.0) {
528 mUnwriteableMargin
.left
= NS_INCHES_TO_TWIPS(aUnwriteableMarginLeft
);
533 /* attribute double unwriteableMarginBottom; */
534 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginBottom(double *aUnwriteableMarginBottom
)
536 NS_ENSURE_ARG_POINTER(aUnwriteableMarginBottom
);
537 *aUnwriteableMarginBottom
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.bottom
);
540 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom
)
542 if (aUnwriteableMarginBottom
>= 0.0) {
543 mUnwriteableMargin
.bottom
= NS_INCHES_TO_TWIPS(aUnwriteableMarginBottom
);
548 /* attribute double unwriteableMarginRight; */
549 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginRight(double *aUnwriteableMarginRight
)
551 NS_ENSURE_ARG_POINTER(aUnwriteableMarginRight
);
552 *aUnwriteableMarginRight
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.right
);
555 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginRight(double aUnwriteableMarginRight
)
557 if (aUnwriteableMarginRight
>= 0.0) {
558 mUnwriteableMargin
.right
= NS_INCHES_TO_TWIPS(aUnwriteableMarginRight
);
563 /* attribute double scaling; */
564 NS_IMETHODIMP
nsPrintSettings::GetScaling(double *aScaling
)
566 NS_ENSURE_ARG_POINTER(aScaling
);
567 *aScaling
= mScaling
;
571 NS_IMETHODIMP
nsPrintSettings::SetScaling(double aScaling
)
577 /* attribute boolean printBGColors; */
578 NS_IMETHODIMP
nsPrintSettings::GetPrintBGColors(PRBool
*aPrintBGColors
)
580 NS_ENSURE_ARG_POINTER(aPrintBGColors
);
581 *aPrintBGColors
= mPrintBGColors
;
584 NS_IMETHODIMP
nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors
)
586 mPrintBGColors
= aPrintBGColors
;
590 /* attribute boolean printBGImages; */
591 NS_IMETHODIMP
nsPrintSettings::GetPrintBGImages(PRBool
*aPrintBGImages
)
593 NS_ENSURE_ARG_POINTER(aPrintBGImages
);
594 *aPrintBGImages
= mPrintBGImages
;
597 NS_IMETHODIMP
nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages
)
599 mPrintBGImages
= aPrintBGImages
;
603 /* attribute long printRange; */
604 NS_IMETHODIMP
nsPrintSettings::GetPrintRange(PRInt16
*aPrintRange
)
606 NS_ENSURE_ARG_POINTER(aPrintRange
);
607 *aPrintRange
= mPrintRange
;
610 NS_IMETHODIMP
nsPrintSettings::SetPrintRange(PRInt16 aPrintRange
)
612 mPrintRange
= aPrintRange
;
616 /* attribute wstring docTitle; */
617 NS_IMETHODIMP
nsPrintSettings::GetTitle(PRUnichar
* *aTitle
)
619 NS_ENSURE_ARG_POINTER(aTitle
);
620 if (!mTitle
.IsEmpty()) {
621 *aTitle
= ToNewUnicode(mTitle
);
627 NS_IMETHODIMP
nsPrintSettings::SetTitle(const PRUnichar
* aTitle
)
637 /* attribute wstring docURL; */
638 NS_IMETHODIMP
nsPrintSettings::GetDocURL(PRUnichar
* *aDocURL
)
640 NS_ENSURE_ARG_POINTER(aDocURL
);
641 if (!mURL
.IsEmpty()) {
642 *aDocURL
= ToNewUnicode(mURL
);
648 NS_IMETHODIMP
nsPrintSettings::SetDocURL(const PRUnichar
* aDocURL
)
658 /** ---------------------------------------------------
659 * See documentation in nsPrintSettingsImpl.h
660 * @update 1/12/01 rods
663 nsPrintSettings::GetPrintOptions(PRInt32 aType
, PRBool
*aTurnOnOff
)
665 NS_ENSURE_ARG_POINTER(aTurnOnOff
);
666 *aTurnOnOff
= mPrintOptions
& aType
? PR_TRUE
: PR_FALSE
;
669 /** ---------------------------------------------------
670 * See documentation in nsPrintSettingsImpl.h
671 * @update 1/12/01 rods
674 nsPrintSettings::SetPrintOptions(PRInt32 aType
, PRBool aTurnOnOff
)
677 mPrintOptions
|= aType
;
679 mPrintOptions
&= ~aType
;
684 /** ---------------------------------------------------
685 * See documentation in nsPrintSettingsImpl.h
686 * @update 1/12/01 rods
689 nsPrintSettings::GetPrintOptionsBits(PRInt32
*aBits
)
691 NS_ENSURE_ARG_POINTER(aBits
);
692 *aBits
= mPrintOptions
;
696 /* attribute wstring docTitle; */
698 nsPrintSettings::GetMarginStrs(PRUnichar
* *aTitle
,
699 nsHeaderFooterEnum aType
,
702 NS_ENSURE_ARG_POINTER(aTitle
);
704 if (aType
== eHeader
) {
706 case kJustLeft
: *aTitle
= ToNewUnicode(mHeaderStrs
[0]);break;
707 case kJustCenter
: *aTitle
= ToNewUnicode(mHeaderStrs
[1]);break;
708 case kJustRight
: *aTitle
= ToNewUnicode(mHeaderStrs
[2]);break;
712 case kJustLeft
: *aTitle
= ToNewUnicode(mFooterStrs
[0]);break;
713 case kJustCenter
: *aTitle
= ToNewUnicode(mFooterStrs
[1]);break;
714 case kJustRight
: *aTitle
= ToNewUnicode(mFooterStrs
[2]);break;
721 nsPrintSettings::SetMarginStrs(const PRUnichar
* aTitle
,
722 nsHeaderFooterEnum aType
,
725 NS_ENSURE_ARG_POINTER(aTitle
);
726 if (aType
== eHeader
) {
728 case kJustLeft
: mHeaderStrs
[0] = aTitle
;break;
729 case kJustCenter
: mHeaderStrs
[1] = aTitle
;break;
730 case kJustRight
: mHeaderStrs
[2] = aTitle
;break;
734 case kJustLeft
: mFooterStrs
[0] = aTitle
;break;
735 case kJustCenter
: mFooterStrs
[1] = aTitle
;break;
736 case kJustRight
: mFooterStrs
[2] = aTitle
;break;
742 /* attribute wstring Header String Left */
743 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrLeft(PRUnichar
* *aTitle
)
745 return GetMarginStrs(aTitle
, eHeader
, kJustLeft
);
747 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrLeft(const PRUnichar
* aTitle
)
749 return SetMarginStrs(aTitle
, eHeader
, kJustLeft
);
752 /* attribute wstring Header String Center */
753 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrCenter(PRUnichar
* *aTitle
)
755 return GetMarginStrs(aTitle
, eHeader
, kJustCenter
);
757 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrCenter(const PRUnichar
* aTitle
)
759 return SetMarginStrs(aTitle
, eHeader
, kJustCenter
);
762 /* attribute wstring Header String Right */
763 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrRight(PRUnichar
* *aTitle
)
765 return GetMarginStrs(aTitle
, eHeader
, kJustRight
);
767 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrRight(const PRUnichar
* aTitle
)
769 return SetMarginStrs(aTitle
, eHeader
, kJustRight
);
773 /* attribute wstring Footer String Left */
774 NS_IMETHODIMP
nsPrintSettings::GetFooterStrLeft(PRUnichar
* *aTitle
)
776 return GetMarginStrs(aTitle
, eFooter
, kJustLeft
);
778 NS_IMETHODIMP
nsPrintSettings::SetFooterStrLeft(const PRUnichar
* aTitle
)
780 return SetMarginStrs(aTitle
, eFooter
, kJustLeft
);
783 /* attribute wstring Footer String Center */
784 NS_IMETHODIMP
nsPrintSettings::GetFooterStrCenter(PRUnichar
* *aTitle
)
786 return GetMarginStrs(aTitle
, eFooter
, kJustCenter
);
788 NS_IMETHODIMP
nsPrintSettings::SetFooterStrCenter(const PRUnichar
* aTitle
)
790 return SetMarginStrs(aTitle
, eFooter
, kJustCenter
);
793 /* attribute wstring Footer String Right */
794 NS_IMETHODIMP
nsPrintSettings::GetFooterStrRight(PRUnichar
* *aTitle
)
796 return GetMarginStrs(aTitle
, eFooter
, kJustRight
);
798 NS_IMETHODIMP
nsPrintSettings::SetFooterStrRight(const PRUnichar
* aTitle
)
800 return SetMarginStrs(aTitle
, eFooter
, kJustRight
);
803 /* attribute short printFrameTypeUsage; */
804 NS_IMETHODIMP
nsPrintSettings::GetPrintFrameTypeUsage(PRInt16
*aPrintFrameTypeUsage
)
806 NS_ENSURE_ARG_POINTER(aPrintFrameTypeUsage
);
807 *aPrintFrameTypeUsage
= mPrintFrameTypeUsage
;
810 NS_IMETHODIMP
nsPrintSettings::SetPrintFrameTypeUsage(PRInt16 aPrintFrameTypeUsage
)
812 mPrintFrameTypeUsage
= aPrintFrameTypeUsage
;
816 /* attribute long printFrameType; */
817 NS_IMETHODIMP
nsPrintSettings::GetPrintFrameType(PRInt16
*aPrintFrameType
)
819 NS_ENSURE_ARG_POINTER(aPrintFrameType
);
820 *aPrintFrameType
= (PRInt32
)mPrintFrameType
;
823 NS_IMETHODIMP
nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType
)
825 mPrintFrameType
= aPrintFrameType
;
829 /* attribute boolean printSilent; */
830 NS_IMETHODIMP
nsPrintSettings::GetPrintSilent(PRBool
*aPrintSilent
)
832 NS_ENSURE_ARG_POINTER(aPrintSilent
);
833 *aPrintSilent
= mPrintSilent
;
836 NS_IMETHODIMP
nsPrintSettings::SetPrintSilent(PRBool aPrintSilent
)
838 mPrintSilent
= aPrintSilent
;
842 /* attribute boolean shrinkToFit; */
843 NS_IMETHODIMP
nsPrintSettings::GetShrinkToFit(PRBool
*aShrinkToFit
)
845 NS_ENSURE_ARG_POINTER(aShrinkToFit
);
846 *aShrinkToFit
= mShrinkToFit
;
849 NS_IMETHODIMP
nsPrintSettings::SetShrinkToFit(PRBool aShrinkToFit
)
851 mShrinkToFit
= aShrinkToFit
;
855 /* attribute boolean showPrintProgress; */
856 NS_IMETHODIMP
nsPrintSettings::GetShowPrintProgress(PRBool
*aShowPrintProgress
)
858 NS_ENSURE_ARG_POINTER(aShowPrintProgress
);
859 *aShowPrintProgress
= mShowPrintProgress
;
862 NS_IMETHODIMP
nsPrintSettings::SetShowPrintProgress(PRBool aShowPrintProgress
)
864 mShowPrintProgress
= aShowPrintProgress
;
868 /* attribute wstring paperName; */
869 NS_IMETHODIMP
nsPrintSettings::GetPaperName(PRUnichar
* *aPaperName
)
871 NS_ENSURE_ARG_POINTER(aPaperName
);
872 if (!mPaperName
.IsEmpty()) {
873 *aPaperName
= ToNewUnicode(mPaperName
);
875 *aPaperName
= nsnull
;
879 NS_IMETHODIMP
nsPrintSettings::SetPaperName(const PRUnichar
* aPaperName
)
882 mPaperName
= aPaperName
;
884 mPaperName
.SetLength(0);
889 /* attribute wstring plexName; */
890 NS_IMETHODIMP
nsPrintSettings::GetPlexName(PRUnichar
* *aPlexName
)
892 NS_ENSURE_ARG_POINTER(aPlexName
);
893 if (!mPlexName
.IsEmpty()) {
894 *aPlexName
= ToNewUnicode(mPlexName
);
900 NS_IMETHODIMP
nsPrintSettings::SetPlexName(const PRUnichar
* aPlexName
)
903 mPlexName
= aPlexName
;
905 mPlexName
.SetLength(0);
910 /* attribute boolean howToEnableFrameUI; */
911 NS_IMETHODIMP
nsPrintSettings::GetHowToEnableFrameUI(PRInt16
*aHowToEnableFrameUI
)
913 NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI
);
914 *aHowToEnableFrameUI
= (PRInt32
)mHowToEnableFrameUI
;
917 NS_IMETHODIMP
nsPrintSettings::SetHowToEnableFrameUI(PRInt16 aHowToEnableFrameUI
)
919 mHowToEnableFrameUI
= aHowToEnableFrameUI
;
923 /* attribute long isCancelled; */
924 NS_IMETHODIMP
nsPrintSettings::GetIsCancelled(PRBool
*aIsCancelled
)
926 NS_ENSURE_ARG_POINTER(aIsCancelled
);
927 *aIsCancelled
= mIsCancelled
;
930 NS_IMETHODIMP
nsPrintSettings::SetIsCancelled(PRBool aIsCancelled
)
932 mIsCancelled
= aIsCancelled
;
936 /* attribute double paperWidth; */
937 NS_IMETHODIMP
nsPrintSettings::GetPaperWidth(double *aPaperWidth
)
939 NS_ENSURE_ARG_POINTER(aPaperWidth
);
940 *aPaperWidth
= mPaperWidth
;
943 NS_IMETHODIMP
nsPrintSettings::SetPaperWidth(double aPaperWidth
)
945 mPaperWidth
= aPaperWidth
;
949 /* attribute double paperHeight; */
950 NS_IMETHODIMP
nsPrintSettings::GetPaperHeight(double *aPaperHeight
)
952 NS_ENSURE_ARG_POINTER(aPaperHeight
);
953 *aPaperHeight
= mPaperHeight
;
956 NS_IMETHODIMP
nsPrintSettings::SetPaperHeight(double aPaperHeight
)
958 mPaperHeight
= aPaperHeight
;
962 /* attribute short PaperSizeUnit; */
963 NS_IMETHODIMP
nsPrintSettings::GetPaperSizeUnit(PRInt16
*aPaperSizeUnit
)
965 NS_ENSURE_ARG_POINTER(aPaperSizeUnit
);
966 *aPaperSizeUnit
= mPaperSizeUnit
;
969 NS_IMETHODIMP
nsPrintSettings::SetPaperSizeUnit(PRInt16 aPaperSizeUnit
)
971 mPaperSizeUnit
= aPaperSizeUnit
;
975 /* attribute short PaperSizeType; */
976 NS_IMETHODIMP
nsPrintSettings::GetPaperSizeType(PRInt16
*aPaperSizeType
)
978 NS_ENSURE_ARG_POINTER(aPaperSizeType
);
979 *aPaperSizeType
= mPaperSizeType
;
982 NS_IMETHODIMP
nsPrintSettings::SetPaperSizeType(PRInt16 aPaperSizeType
)
984 mPaperSizeType
= aPaperSizeType
;
988 /* attribute short PaperData; */
989 NS_IMETHODIMP
nsPrintSettings::GetPaperData(PRInt16
*aPaperData
)
991 NS_ENSURE_ARG_POINTER(aPaperData
);
992 *aPaperData
= mPaperData
;
995 NS_IMETHODIMP
nsPrintSettings::SetPaperData(PRInt16 aPaperData
)
997 mPaperData
= aPaperData
;
1001 /** ---------------------------------------------------
1002 * See documentation in nsPrintOptionsImpl.h
1003 * @update 6/21/00 dwc
1004 * @update 1/12/01 rods
1007 nsPrintSettings::SetMarginInTwips(nsMargin
& aMargin
)
1014 nsPrintSettings::SetEdgeInTwips(nsMargin
& aEdge
)
1020 // NOTE: Any subclass implementation of this function should make sure
1021 // to check for negative margin values in aUnwriteableMargin (which
1022 // would indicate that we should use the system default unwriteable margin.)
1024 nsPrintSettings::SetUnwriteableMarginInTwips(nsMargin
& aUnwriteableMargin
)
1026 if (aUnwriteableMargin
.top
>= 0) {
1027 mUnwriteableMargin
.top
= aUnwriteableMargin
.top
;
1029 if (aUnwriteableMargin
.left
>= 0) {
1030 mUnwriteableMargin
.left
= aUnwriteableMargin
.left
;
1032 if (aUnwriteableMargin
.bottom
>= 0) {
1033 mUnwriteableMargin
.bottom
= aUnwriteableMargin
.bottom
;
1035 if (aUnwriteableMargin
.right
>= 0) {
1036 mUnwriteableMargin
.right
= aUnwriteableMargin
.right
;
1041 /** ---------------------------------------------------
1042 * See documentation in nsPrintOptionsImpl.h
1043 * @update 6/21/00 dwc
1046 nsPrintSettings::GetMarginInTwips(nsMargin
& aMargin
)
1053 nsPrintSettings::GetEdgeInTwips(nsMargin
& aEdge
)
1060 nsPrintSettings::GetUnwriteableMarginInTwips(nsMargin
& aUnwriteableMargin
)
1062 aUnwriteableMargin
= mUnwriteableMargin
;
1066 /** ---------------------------------------------------
1067 * Stub - platform-specific implementations can use this function.
1070 nsPrintSettings::SetupSilentPrinting()
1075 /** ---------------------------------------------------
1076 * See documentation in nsPrintOptionsImpl.h
1079 nsPrintSettings::GetEffectivePageSize(double *aWidth
, double *aHeight
)
1081 if (mPaperSizeUnit
== kPaperSizeInches
) {
1082 *aWidth
= NS_INCHES_TO_TWIPS(float(mPaperWidth
));
1083 *aHeight
= NS_INCHES_TO_TWIPS(float(mPaperHeight
));
1085 *aWidth
= NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth
));
1086 *aHeight
= NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight
));
1088 if (kLandscapeOrientation
== mOrientation
) {
1089 double temp
= *aWidth
;
1097 nsPrintSettings::_Clone(nsIPrintSettings
**_retval
)
1099 nsPrintSettings
* printSettings
= new nsPrintSettings(*this);
1100 return printSettings
->QueryInterface(NS_GET_IID(nsIPrintSettings
), (void**)_retval
); // ref counts
1103 /* nsIPrintSettings clone (); */
1105 nsPrintSettings::Clone(nsIPrintSettings
**_retval
)
1107 NS_ENSURE_ARG_POINTER(_retval
);
1108 return _Clone(_retval
);
1111 /* void assign (in nsIPrintSettings aPS); */
1113 nsPrintSettings::_Assign(nsIPrintSettings
*aPS
)
1115 nsPrintSettings
*ps
= static_cast<nsPrintSettings
*>(aPS
);
1120 /* void assign (in nsIPrintSettings aPS); */
1122 nsPrintSettings::Assign(nsIPrintSettings
*aPS
)
1125 return _Assign(aPS
);
1128 //-------------------------------------------
1129 nsPrintSettings
& nsPrintSettings::operator=(const nsPrintSettings
& rhs
)
1135 mStartPageNum
= rhs
.mStartPageNum
;
1136 mEndPageNum
= rhs
.mEndPageNum
;
1137 mMargin
= rhs
.mMargin
;
1139 mUnwriteableMargin
= rhs
.mUnwriteableMargin
;
1140 mScaling
= rhs
.mScaling
;
1141 mPrintBGColors
= rhs
.mPrintBGColors
;
1142 mPrintBGImages
= rhs
.mPrintBGImages
;
1143 mPrintRange
= rhs
.mPrintRange
;
1144 mTitle
= rhs
.mTitle
;
1146 mHowToEnableFrameUI
= rhs
.mHowToEnableFrameUI
;
1147 mIsCancelled
= rhs
.mIsCancelled
;
1148 mPrintFrameTypeUsage
= rhs
.mPrintFrameTypeUsage
;
1149 mPrintFrameType
= rhs
.mPrintFrameType
;
1150 mPrintSilent
= rhs
.mPrintSilent
;
1151 mShrinkToFit
= rhs
.mShrinkToFit
;
1152 mShowPrintProgress
= rhs
.mShowPrintProgress
;
1153 mPaperName
= rhs
.mPaperName
;
1154 mPlexName
= rhs
.mPlexName
;
1155 mPaperSizeType
= rhs
.mPaperSizeType
;
1156 mPaperData
= rhs
.mPaperData
;
1157 mPaperWidth
= rhs
.mPaperWidth
;
1158 mPaperHeight
= rhs
.mPaperHeight
;
1159 mPaperSizeUnit
= rhs
.mPaperSizeUnit
;
1160 mPrintReversed
= rhs
.mPrintReversed
;
1161 mPrintInColor
= rhs
.mPrintInColor
;
1162 mOrientation
= rhs
.mOrientation
;
1163 mPrintCommand
= rhs
.mPrintCommand
;
1164 mNumCopies
= rhs
.mNumCopies
;
1165 mPrinter
= rhs
.mPrinter
;
1166 mPrintToFile
= rhs
.mPrintToFile
;
1167 mToFileName
= rhs
.mToFileName
;
1168 mOutputFormat
= rhs
.mOutputFormat
;
1169 mPrintPageDelay
= rhs
.mPrintPageDelay
;
1171 for (PRInt32 i
=0;i
<NUM_HEAD_FOOT
;i
++) {
1172 mHeaderStrs
[i
] = rhs
.mHeaderStrs
[i
];
1173 mFooterStrs
[i
] = rhs
.mFooterStrs
[i
];