Bug 1640914 [wpt PR 23771] - Python 3: port tests in resource-timing, a=testonly
[gecko.git] / widget / nsPrintSettingsImpl.cpp
blob27f17f89d87b564448673e6fab51e66325d2c3a2
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"
9 #include "mozilla/RefPtr.h"
11 #define DEFAULT_MARGIN_WIDTH 0.5
13 NS_IMPL_ISUPPORTS(nsPrintSettings, nsIPrintSettings)
15 nsPrintSettings::nsPrintSettings()
16 : mPrintOptions(0L),
17 mPrintRange(kRangeAllPages),
18 mStartPageNum(1),
19 mEndPageNum(1),
20 mScaling(1.0),
21 mPrintBGColors(false),
22 mPrintBGImages(false),
23 mIsCancelled(false),
24 mSaveOnCancel(true),
25 mPrintSilent(false),
26 mShrinkToFit(true),
27 mShowPrintProgress(true),
28 mPrintPageDelay(50),
29 mPaperData(0),
30 mPaperWidth(8.5),
31 mPaperHeight(11.0),
32 mPaperSizeUnit(kPaperSizeInches),
33 mPrintReversed(false),
34 mPrintInColor(true),
35 mOrientation(kPortraitOrientation),
36 mResolution(0),
37 mDuplex(0),
38 mNumCopies(1),
39 mPrintToFile(false),
40 mOutputFormat(kOutputFormatNative),
41 mIsInitedFromPrinter(false),
42 mIsInitedFromPrefs(false) {
43 /* member initializers and constructor code */
44 int32_t marginWidth = NS_INCHES_TO_INT_TWIPS(DEFAULT_MARGIN_WIDTH);
45 mMargin.SizeTo(marginWidth, marginWidth, marginWidth, marginWidth);
46 mEdge.SizeTo(0, 0, 0, 0);
47 mUnwriteableMargin.SizeTo(0, 0, 0, 0);
49 mPrintOptions = kPrintOddPages | kPrintEvenPages;
51 mHeaderStrs[0].AssignLiteral("&T");
52 mHeaderStrs[2].AssignLiteral("&U");
54 mFooterStrs[0].AssignLiteral(
55 "&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
56 mFooterStrs[2].AssignLiteral("&D");
59 nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS) { *this = aPS; }
61 nsPrintSettings::~nsPrintSettings() = default;
63 NS_IMETHODIMP nsPrintSettings::GetPrintSession(
64 nsIPrintSession** aPrintSession) {
65 NS_ENSURE_ARG_POINTER(aPrintSession);
66 *aPrintSession = nullptr;
68 nsCOMPtr<nsIPrintSession> session = do_QueryReferent(mSession);
69 if (!session) return NS_ERROR_NOT_INITIALIZED;
70 *aPrintSession = session;
71 NS_ADDREF(*aPrintSession);
72 return NS_OK;
74 NS_IMETHODIMP nsPrintSettings::SetPrintSession(nsIPrintSession* aPrintSession) {
75 // Clearing it by passing nullptr is not allowed. That's why we
76 // use a weak ref so that it doesn't have to be cleared.
77 NS_ENSURE_ARG(aPrintSession);
79 mSession = do_GetWeakReference(aPrintSession);
80 if (!mSession) {
81 // This may happen if the implementation of this object does
82 // not support weak references - programmer error.
83 NS_ERROR("Could not get a weak reference from aPrintSession");
84 return NS_ERROR_FAILURE;
86 return NS_OK;
89 NS_IMETHODIMP nsPrintSettings::GetStartPageRange(int32_t* aStartPageRange) {
90 // NS_ENSURE_ARG_POINTER(aStartPageRange);
91 *aStartPageRange = mStartPageNum;
92 return NS_OK;
94 NS_IMETHODIMP nsPrintSettings::SetStartPageRange(int32_t aStartPageRange) {
95 mStartPageNum = aStartPageRange;
96 return NS_OK;
99 NS_IMETHODIMP nsPrintSettings::GetEndPageRange(int32_t* aEndPageRange) {
100 // NS_ENSURE_ARG_POINTER(aEndPageRange);
101 *aEndPageRange = mEndPageNum;
102 return NS_OK;
104 NS_IMETHODIMP nsPrintSettings::SetEndPageRange(int32_t aEndPageRange) {
105 mEndPageNum = aEndPageRange;
106 return NS_OK;
109 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(bool* aPrintReversed) {
110 // NS_ENSURE_ARG_POINTER(aPrintReversed);
111 *aPrintReversed = mPrintReversed;
112 return NS_OK;
114 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(bool aPrintReversed) {
115 mPrintReversed = aPrintReversed;
116 return NS_OK;
119 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(bool* aPrintInColor) {
120 // NS_ENSURE_ARG_POINTER(aPrintInColor);
121 *aPrintInColor = mPrintInColor;
122 return NS_OK;
124 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(bool aPrintInColor) {
125 mPrintInColor = aPrintInColor;
126 return NS_OK;
129 NS_IMETHODIMP nsPrintSettings::GetOrientation(int32_t* aOrientation) {
130 NS_ENSURE_ARG_POINTER(aOrientation);
131 *aOrientation = mOrientation;
132 return NS_OK;
134 NS_IMETHODIMP nsPrintSettings::SetOrientation(int32_t aOrientation) {
135 mOrientation = aOrientation;
136 return NS_OK;
139 NS_IMETHODIMP nsPrintSettings::GetResolution(int32_t* aResolution) {
140 NS_ENSURE_ARG_POINTER(aResolution);
141 *aResolution = mResolution;
142 return NS_OK;
144 NS_IMETHODIMP nsPrintSettings::SetResolution(const int32_t aResolution) {
145 mResolution = aResolution;
146 return NS_OK;
149 NS_IMETHODIMP nsPrintSettings::GetDuplex(int32_t* aDuplex) {
150 NS_ENSURE_ARG_POINTER(aDuplex);
151 *aDuplex = mDuplex;
152 return NS_OK;
154 NS_IMETHODIMP nsPrintSettings::SetDuplex(const int32_t aDuplex) {
155 mDuplex = aDuplex;
156 return NS_OK;
159 NS_IMETHODIMP nsPrintSettings::GetPrinterName(nsAString& aPrinter) {
160 aPrinter = mPrinter;
161 return NS_OK;
164 NS_IMETHODIMP nsPrintSettings::SetPrinterName(const nsAString& aPrinter) {
165 if (!mPrinter.Equals(aPrinter)) {
166 mIsInitedFromPrinter = false;
167 mIsInitedFromPrefs = false;
170 mPrinter.Assign(aPrinter);
171 return NS_OK;
174 NS_IMETHODIMP nsPrintSettings::GetNumCopies(int32_t* aNumCopies) {
175 NS_ENSURE_ARG_POINTER(aNumCopies);
176 *aNumCopies = mNumCopies;
177 return NS_OK;
179 NS_IMETHODIMP nsPrintSettings::SetNumCopies(int32_t aNumCopies) {
180 mNumCopies = aNumCopies;
181 return NS_OK;
184 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(bool* aPrintToFile) {
185 // NS_ENSURE_ARG_POINTER(aPrintToFile);
186 *aPrintToFile = mPrintToFile;
187 return NS_OK;
189 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(bool aPrintToFile) {
190 mPrintToFile = aPrintToFile;
191 return NS_OK;
194 NS_IMETHODIMP nsPrintSettings::GetToFileName(nsAString& aToFileName) {
195 aToFileName = mToFileName;
196 return NS_OK;
198 NS_IMETHODIMP nsPrintSettings::SetToFileName(const nsAString& aToFileName) {
199 mToFileName = aToFileName;
200 return NS_OK;
203 NS_IMETHODIMP nsPrintSettings::GetOutputFormat(int16_t* aOutputFormat) {
204 NS_ENSURE_ARG_POINTER(aOutputFormat);
205 *aOutputFormat = mOutputFormat;
206 return NS_OK;
208 NS_IMETHODIMP nsPrintSettings::SetOutputFormat(int16_t aOutputFormat) {
209 mOutputFormat = aOutputFormat;
210 return NS_OK;
213 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(int32_t* aPrintPageDelay) {
214 *aPrintPageDelay = mPrintPageDelay;
215 return NS_OK;
217 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(int32_t aPrintPageDelay) {
218 mPrintPageDelay = aPrintPageDelay;
219 return NS_OK;
222 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrinter(
223 bool* aIsInitializedFromPrinter) {
224 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter);
225 *aIsInitializedFromPrinter = (bool)mIsInitedFromPrinter;
226 return NS_OK;
228 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrinter(
229 bool aIsInitializedFromPrinter) {
230 mIsInitedFromPrinter = (bool)aIsInitializedFromPrinter;
231 return NS_OK;
234 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrefs(
235 bool* aInitializedFromPrefs) {
236 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs);
237 *aInitializedFromPrefs = (bool)mIsInitedFromPrefs;
238 return NS_OK;
240 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(
241 bool aInitializedFromPrefs) {
242 mIsInitedFromPrefs = (bool)aInitializedFromPrefs;
243 return NS_OK;
246 NS_IMETHODIMP nsPrintSettings::GetMarginTop(double* aMarginTop) {
247 NS_ENSURE_ARG_POINTER(aMarginTop);
248 *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
249 return NS_OK;
251 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop) {
252 mMargin.top = NS_INCHES_TO_INT_TWIPS(float(aMarginTop));
253 return NS_OK;
256 NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double* aMarginLeft) {
257 NS_ENSURE_ARG_POINTER(aMarginLeft);
258 *aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
259 return NS_OK;
261 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft) {
262 mMargin.left = NS_INCHES_TO_INT_TWIPS(float(aMarginLeft));
263 return NS_OK;
266 NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double* aMarginBottom) {
267 NS_ENSURE_ARG_POINTER(aMarginBottom);
268 *aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
269 return NS_OK;
271 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom) {
272 mMargin.bottom = NS_INCHES_TO_INT_TWIPS(float(aMarginBottom));
273 return NS_OK;
276 NS_IMETHODIMP nsPrintSettings::GetMarginRight(double* aMarginRight) {
277 NS_ENSURE_ARG_POINTER(aMarginRight);
278 *aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
279 return NS_OK;
281 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight) {
282 mMargin.right = NS_INCHES_TO_INT_TWIPS(float(aMarginRight));
283 return NS_OK;
286 NS_IMETHODIMP nsPrintSettings::GetEdgeTop(double* aEdgeTop) {
287 NS_ENSURE_ARG_POINTER(aEdgeTop);
288 *aEdgeTop = NS_TWIPS_TO_INCHES(mEdge.top);
289 return NS_OK;
291 NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop) {
292 mEdge.top = NS_INCHES_TO_INT_TWIPS(float(aEdgeTop));
293 return NS_OK;
296 NS_IMETHODIMP nsPrintSettings::GetEdgeLeft(double* aEdgeLeft) {
297 NS_ENSURE_ARG_POINTER(aEdgeLeft);
298 *aEdgeLeft = NS_TWIPS_TO_INCHES(mEdge.left);
299 return NS_OK;
301 NS_IMETHODIMP nsPrintSettings::SetEdgeLeft(double aEdgeLeft) {
302 mEdge.left = NS_INCHES_TO_INT_TWIPS(float(aEdgeLeft));
303 return NS_OK;
306 NS_IMETHODIMP nsPrintSettings::GetEdgeBottom(double* aEdgeBottom) {
307 NS_ENSURE_ARG_POINTER(aEdgeBottom);
308 *aEdgeBottom = NS_TWIPS_TO_INCHES(mEdge.bottom);
309 return NS_OK;
311 NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom) {
312 mEdge.bottom = NS_INCHES_TO_INT_TWIPS(float(aEdgeBottom));
313 return NS_OK;
316 NS_IMETHODIMP nsPrintSettings::GetEdgeRight(double* aEdgeRight) {
317 NS_ENSURE_ARG_POINTER(aEdgeRight);
318 *aEdgeRight = NS_TWIPS_TO_INCHES(mEdge.right);
319 return NS_OK;
321 NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight) {
322 mEdge.right = NS_INCHES_TO_INT_TWIPS(float(aEdgeRight));
323 return NS_OK;
326 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginTop(
327 double* aUnwriteableMarginTop) {
328 NS_ENSURE_ARG_POINTER(aUnwriteableMarginTop);
329 *aUnwriteableMarginTop = NS_TWIPS_TO_INCHES(mUnwriteableMargin.top);
330 return NS_OK;
332 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginTop(
333 double aUnwriteableMarginTop) {
334 if (aUnwriteableMarginTop >= 0.0) {
335 mUnwriteableMargin.top = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginTop);
337 return NS_OK;
340 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginLeft(
341 double* aUnwriteableMarginLeft) {
342 NS_ENSURE_ARG_POINTER(aUnwriteableMarginLeft);
343 *aUnwriteableMarginLeft = NS_TWIPS_TO_INCHES(mUnwriteableMargin.left);
344 return NS_OK;
346 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginLeft(
347 double aUnwriteableMarginLeft) {
348 if (aUnwriteableMarginLeft >= 0.0) {
349 mUnwriteableMargin.left = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginLeft);
351 return NS_OK;
354 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginBottom(
355 double* aUnwriteableMarginBottom) {
356 NS_ENSURE_ARG_POINTER(aUnwriteableMarginBottom);
357 *aUnwriteableMarginBottom = NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom);
358 return NS_OK;
360 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginBottom(
361 double aUnwriteableMarginBottom) {
362 if (aUnwriteableMarginBottom >= 0.0) {
363 mUnwriteableMargin.bottom =
364 NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginBottom);
366 return NS_OK;
369 NS_IMETHODIMP nsPrintSettings::GetUnwriteableMarginRight(
370 double* aUnwriteableMarginRight) {
371 NS_ENSURE_ARG_POINTER(aUnwriteableMarginRight);
372 *aUnwriteableMarginRight = NS_TWIPS_TO_INCHES(mUnwriteableMargin.right);
373 return NS_OK;
375 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginRight(
376 double aUnwriteableMarginRight) {
377 if (aUnwriteableMarginRight >= 0.0) {
378 mUnwriteableMargin.right = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginRight);
380 return NS_OK;
383 NS_IMETHODIMP nsPrintSettings::GetScaling(double* aScaling) {
384 NS_ENSURE_ARG_POINTER(aScaling);
385 *aScaling = mScaling;
386 return NS_OK;
389 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling) {
390 mScaling = aScaling;
391 return NS_OK;
394 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(bool* aPrintBGColors) {
395 NS_ENSURE_ARG_POINTER(aPrintBGColors);
396 *aPrintBGColors = mPrintBGColors;
397 return NS_OK;
399 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(bool aPrintBGColors) {
400 mPrintBGColors = aPrintBGColors;
401 return NS_OK;
404 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(bool* aPrintBGImages) {
405 NS_ENSURE_ARG_POINTER(aPrintBGImages);
406 *aPrintBGImages = mPrintBGImages;
407 return NS_OK;
409 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(bool aPrintBGImages) {
410 mPrintBGImages = aPrintBGImages;
411 return NS_OK;
414 NS_IMETHODIMP nsPrintSettings::GetPrintRange(int16_t* aPrintRange) {
415 NS_ENSURE_ARG_POINTER(aPrintRange);
416 *aPrintRange = mPrintRange;
417 return NS_OK;
419 NS_IMETHODIMP nsPrintSettings::SetPrintRange(int16_t aPrintRange) {
420 mPrintRange = aPrintRange;
421 return NS_OK;
424 NS_IMETHODIMP nsPrintSettings::GetTitle(nsAString& aTitle) {
425 aTitle = mTitle;
426 return NS_OK;
428 NS_IMETHODIMP nsPrintSettings::SetTitle(const nsAString& aTitle) {
429 mTitle = aTitle;
430 return NS_OK;
433 NS_IMETHODIMP nsPrintSettings::GetDocURL(nsAString& aDocURL) {
434 aDocURL = mURL;
435 return NS_OK;
437 NS_IMETHODIMP nsPrintSettings::SetDocURL(const nsAString& aDocURL) {
438 mURL = aDocURL;
439 return NS_OK;
442 /** ---------------------------------------------------
443 * See documentation in nsPrintSettingsImpl.h
444 * @update 1/12/01 rods
446 NS_IMETHODIMP
447 nsPrintSettings::GetPrintOptions(int32_t aType, bool* aTurnOnOff) {
448 NS_ENSURE_ARG_POINTER(aTurnOnOff);
449 *aTurnOnOff = mPrintOptions & aType ? true : false;
450 return NS_OK;
452 /** ---------------------------------------------------
453 * See documentation in nsPrintSettingsImpl.h
454 * @update 1/12/01 rods
456 NS_IMETHODIMP
457 nsPrintSettings::SetPrintOptions(int32_t aType, bool aTurnOnOff) {
458 if (aTurnOnOff) {
459 mPrintOptions |= aType;
460 } else {
461 mPrintOptions &= ~aType;
463 return NS_OK;
466 /** ---------------------------------------------------
467 * See documentation in nsPrintSettingsImpl.h
468 * @update 1/12/01 rods
470 NS_IMETHODIMP
471 nsPrintSettings::GetPrintOptionsBits(int32_t* aBits) {
472 NS_ENSURE_ARG_POINTER(aBits);
473 *aBits = mPrintOptions;
474 return NS_OK;
477 NS_IMETHODIMP
478 nsPrintSettings::SetPrintOptionsBits(int32_t aBits) {
479 mPrintOptions = aBits;
480 return NS_OK;
483 NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(nsAString& aTitle) {
484 aTitle = mHeaderStrs[0];
485 return NS_OK;
487 NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const nsAString& aTitle) {
488 mHeaderStrs[0] = aTitle;
489 return NS_OK;
492 NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(nsAString& aTitle) {
493 aTitle = mHeaderStrs[1];
494 return NS_OK;
496 NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const nsAString& aTitle) {
497 mHeaderStrs[1] = aTitle;
498 return NS_OK;
501 NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(nsAString& aTitle) {
502 aTitle = mHeaderStrs[2];
503 return NS_OK;
505 NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const nsAString& aTitle) {
506 mHeaderStrs[2] = aTitle;
507 return NS_OK;
510 NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(nsAString& aTitle) {
511 aTitle = mFooterStrs[0];
512 return NS_OK;
514 NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const nsAString& aTitle) {
515 mFooterStrs[0] = aTitle;
516 return NS_OK;
519 NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(nsAString& aTitle) {
520 aTitle = mFooterStrs[1];
521 return NS_OK;
523 NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const nsAString& aTitle) {
524 mFooterStrs[1] = aTitle;
525 return NS_OK;
528 NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(nsAString& aTitle) {
529 aTitle = mFooterStrs[2];
530 return NS_OK;
532 NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const nsAString& aTitle) {
533 mFooterStrs[2] = aTitle;
534 return NS_OK;
537 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(bool* aPrintSilent) {
538 NS_ENSURE_ARG_POINTER(aPrintSilent);
539 *aPrintSilent = mPrintSilent;
540 return NS_OK;
542 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(bool aPrintSilent) {
543 mPrintSilent = aPrintSilent;
544 return NS_OK;
547 NS_IMETHODIMP nsPrintSettings::GetShrinkToFit(bool* aShrinkToFit) {
548 NS_ENSURE_ARG_POINTER(aShrinkToFit);
549 *aShrinkToFit = mShrinkToFit;
550 return NS_OK;
552 NS_IMETHODIMP nsPrintSettings::SetShrinkToFit(bool aShrinkToFit) {
553 mShrinkToFit = aShrinkToFit;
554 return NS_OK;
557 NS_IMETHODIMP nsPrintSettings::GetShowPrintProgress(bool* aShowPrintProgress) {
558 NS_ENSURE_ARG_POINTER(aShowPrintProgress);
559 *aShowPrintProgress = mShowPrintProgress;
560 return NS_OK;
562 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress) {
563 mShowPrintProgress = aShowPrintProgress;
564 return NS_OK;
567 NS_IMETHODIMP nsPrintSettings::GetPaperName(nsAString& aPaperName) {
568 aPaperName = mPaperName;
569 return NS_OK;
571 NS_IMETHODIMP nsPrintSettings::SetPaperName(const nsAString& aPaperName) {
572 mPaperName = aPaperName;
573 return NS_OK;
576 NS_IMETHODIMP nsPrintSettings::GetIsCancelled(bool* aIsCancelled) {
577 NS_ENSURE_ARG_POINTER(aIsCancelled);
578 *aIsCancelled = mIsCancelled;
579 return NS_OK;
581 NS_IMETHODIMP nsPrintSettings::SetIsCancelled(bool aIsCancelled) {
582 mIsCancelled = aIsCancelled;
583 return NS_OK;
586 NS_IMETHODIMP nsPrintSettings::GetSaveOnCancel(bool* aSaveOnCancel) {
587 *aSaveOnCancel = mSaveOnCancel;
588 return NS_OK;
591 NS_IMETHODIMP nsPrintSettings::GetPaperWidth(double* aPaperWidth) {
592 NS_ENSURE_ARG_POINTER(aPaperWidth);
593 *aPaperWidth = mPaperWidth;
594 return NS_OK;
596 NS_IMETHODIMP nsPrintSettings::SetPaperWidth(double aPaperWidth) {
597 mPaperWidth = aPaperWidth;
598 return NS_OK;
601 NS_IMETHODIMP nsPrintSettings::GetPaperHeight(double* aPaperHeight) {
602 NS_ENSURE_ARG_POINTER(aPaperHeight);
603 *aPaperHeight = mPaperHeight;
604 return NS_OK;
606 NS_IMETHODIMP nsPrintSettings::SetPaperHeight(double aPaperHeight) {
607 mPaperHeight = aPaperHeight;
608 return NS_OK;
611 NS_IMETHODIMP nsPrintSettings::GetPaperSizeUnit(int16_t* aPaperSizeUnit) {
612 NS_ENSURE_ARG_POINTER(aPaperSizeUnit);
613 *aPaperSizeUnit = mPaperSizeUnit;
614 return NS_OK;
616 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit) {
617 mPaperSizeUnit = aPaperSizeUnit;
618 return NS_OK;
621 NS_IMETHODIMP nsPrintSettings::GetPaperData(int16_t* aPaperData) {
622 NS_ENSURE_ARG_POINTER(aPaperData);
623 *aPaperData = mPaperData;
624 return NS_OK;
626 NS_IMETHODIMP nsPrintSettings::SetPaperData(int16_t aPaperData) {
627 mPaperData = aPaperData;
628 return NS_OK;
631 /** ---------------------------------------------------
632 * See documentation in nsPrintSettingsService.h
633 * @update 6/21/00 dwc
634 * @update 1/12/01 rods
636 NS_IMETHODIMP
637 nsPrintSettings::SetMarginInTwips(nsIntMargin& aMargin) {
638 mMargin = aMargin;
639 return NS_OK;
642 NS_IMETHODIMP
643 nsPrintSettings::SetEdgeInTwips(nsIntMargin& aEdge) {
644 mEdge = aEdge;
645 return NS_OK;
648 // NOTE: Any subclass implementation of this function should make sure
649 // to check for negative margin values in aUnwriteableMargin (which
650 // would indicate that we should use the system default unwriteable margin.)
651 NS_IMETHODIMP
652 nsPrintSettings::SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin) {
653 if (aUnwriteableMargin.top >= 0) {
654 mUnwriteableMargin.top = aUnwriteableMargin.top;
656 if (aUnwriteableMargin.left >= 0) {
657 mUnwriteableMargin.left = aUnwriteableMargin.left;
659 if (aUnwriteableMargin.bottom >= 0) {
660 mUnwriteableMargin.bottom = aUnwriteableMargin.bottom;
662 if (aUnwriteableMargin.right >= 0) {
663 mUnwriteableMargin.right = aUnwriteableMargin.right;
665 return NS_OK;
668 /** ---------------------------------------------------
669 * See documentation in nsPrintSettingsService.h
670 * @update 6/21/00 dwc
672 NS_IMETHODIMP
673 nsPrintSettings::GetMarginInTwips(nsIntMargin& aMargin) {
674 aMargin = mMargin;
675 return NS_OK;
678 NS_IMETHODIMP
679 nsPrintSettings::GetEdgeInTwips(nsIntMargin& aEdge) {
680 aEdge = mEdge;
681 return NS_OK;
684 NS_IMETHODIMP
685 nsPrintSettings::GetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin) {
686 aUnwriteableMargin = mUnwriteableMargin;
687 return NS_OK;
690 /** ---------------------------------------------------
691 * Stub - platform-specific implementations can use this function.
693 NS_IMETHODIMP
694 nsPrintSettings::SetupSilentPrinting() { return NS_OK; }
696 /** ---------------------------------------------------
697 * See documentation in nsPrintSettingsService.h
699 NS_IMETHODIMP
700 nsPrintSettings::GetEffectivePageSize(double* aWidth, double* aHeight) {
701 if (mPaperSizeUnit == kPaperSizeInches) {
702 *aWidth = NS_INCHES_TO_TWIPS(float(mPaperWidth));
703 *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight));
704 } else {
705 *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth));
706 *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight));
708 if (kLandscapeOrientation == mOrientation) {
709 double temp = *aWidth;
710 *aWidth = *aHeight;
711 *aHeight = temp;
713 return NS_OK;
716 NS_IMETHODIMP
717 nsPrintSettings::GetPageRanges(nsTArray<int32_t>& aPages) {
718 aPages.Clear();
719 return NS_OK;
722 nsresult nsPrintSettings::_Clone(nsIPrintSettings** _retval) {
723 RefPtr<nsPrintSettings> printSettings = new nsPrintSettings(*this);
724 printSettings.forget(_retval);
725 return NS_OK;
728 NS_IMETHODIMP
729 nsPrintSettings::Clone(nsIPrintSettings** _retval) {
730 NS_ENSURE_ARG_POINTER(_retval);
731 return _Clone(_retval);
734 nsresult nsPrintSettings::_Assign(nsIPrintSettings* aPS) {
735 nsPrintSettings* ps = static_cast<nsPrintSettings*>(aPS);
736 *this = *ps;
737 return NS_OK;
740 NS_IMETHODIMP
741 nsPrintSettings::Assign(nsIPrintSettings* aPS) {
742 NS_ENSURE_ARG(aPS);
743 return _Assign(aPS);
746 //-------------------------------------------
747 nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) {
748 if (this == &rhs) {
749 return *this;
752 mStartPageNum = rhs.mStartPageNum;
753 mEndPageNum = rhs.mEndPageNum;
754 mMargin = rhs.mMargin;
755 mEdge = rhs.mEdge;
756 mUnwriteableMargin = rhs.mUnwriteableMargin;
757 mScaling = rhs.mScaling;
758 mPrintBGColors = rhs.mPrintBGColors;
759 mPrintBGImages = rhs.mPrintBGImages;
760 mPrintRange = rhs.mPrintRange;
761 mTitle = rhs.mTitle;
762 mURL = rhs.mURL;
763 mIsCancelled = rhs.mIsCancelled;
764 mPrintSilent = rhs.mPrintSilent;
765 mShrinkToFit = rhs.mShrinkToFit;
766 mShowPrintProgress = rhs.mShowPrintProgress;
767 mPaperName = rhs.mPaperName;
768 mPaperData = rhs.mPaperData;
769 mPaperWidth = rhs.mPaperWidth;
770 mPaperHeight = rhs.mPaperHeight;
771 mPaperSizeUnit = rhs.mPaperSizeUnit;
772 mPrintReversed = rhs.mPrintReversed;
773 mPrintInColor = rhs.mPrintInColor;
774 mOrientation = rhs.mOrientation;
775 mNumCopies = rhs.mNumCopies;
776 mPrinter = rhs.mPrinter;
777 mPrintToFile = rhs.mPrintToFile;
778 mToFileName = rhs.mToFileName;
779 mOutputFormat = rhs.mOutputFormat;
780 mPrintPageDelay = rhs.mPrintPageDelay;
782 for (int32_t i = 0; i < NUM_HEAD_FOOT; i++) {
783 mHeaderStrs[i] = rhs.mHeaderStrs[i];
784 mFooterStrs[i] = rhs.mFooterStrs[i];
787 return *this;