Bug 1073336 part 5 - Add AnimationPlayerCollection::PlayerUpdated; r=dbaron
[gecko.git] / widget / nsPrintSettingsImpl.cpp
blobd7d59e0f2dd29aaf4d8c906d3a31611c861c88a3
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
16 * @update 6/21/00 dwc
18 nsPrintSettings::nsPrintSettings() :
19 mPrintOptions(0L),
20 mPrintRange(kRangeAllPages),
21 mStartPageNum(1),
22 mEndPageNum(1),
23 mScaling(1.0),
24 mPrintBGColors(false),
25 mPrintBGImages(false),
26 mPrintFrameTypeUsage(kUseInternalDefault),
27 mPrintFrameType(kFramesAsIs),
28 mHowToEnableFrameUI(kFrameEnableNone),
29 mIsCancelled(false),
30 mPrintSilent(false),
31 mPrintPreview(false),
32 mShrinkToFit(true),
33 mShowPrintProgress(true),
34 mPrintPageDelay(50),
35 mPaperData(0),
36 mPaperSizeType(kPaperSizeDefined),
37 mPaperWidth(8.5),
38 mPaperHeight(11.0),
39 mPaperSizeUnit(kPaperSizeInches),
40 mPrintReversed(false),
41 mPrintInColor(true),
42 mOrientation(kPortraitOrientation),
43 mDownloadFonts(false),
44 mNumCopies(1),
45 mPrintToFile(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
70 * @update 6/21/00 dwc
72 nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS)
74 *this = aPS;
77 /** ---------------------------------------------------
78 * See documentation in nsPrintSettingsImpl.h
79 * @update 6/21/00 dwc
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);
92 if (!session)
93 return NS_ERROR_NOT_INITIALIZED;
94 *aPrintSession = session;
95 NS_ADDREF(*aPrintSession);
96 return NS_OK;
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);
105 if (!mSession) {
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;
111 return NS_OK;
114 /* attribute long startPageRange; */
115 NS_IMETHODIMP nsPrintSettings::GetStartPageRange(int32_t *aStartPageRange)
117 //NS_ENSURE_ARG_POINTER(aStartPageRange);
118 *aStartPageRange = mStartPageNum;
119 return NS_OK;
121 NS_IMETHODIMP nsPrintSettings::SetStartPageRange(int32_t aStartPageRange)
123 mStartPageNum = aStartPageRange;
124 return NS_OK;
127 /* attribute long endPageRange; */
128 NS_IMETHODIMP nsPrintSettings::GetEndPageRange(int32_t *aEndPageRange)
130 //NS_ENSURE_ARG_POINTER(aEndPageRange);
131 *aEndPageRange = mEndPageNum;
132 return NS_OK;
134 NS_IMETHODIMP nsPrintSettings::SetEndPageRange(int32_t aEndPageRange)
136 mEndPageNum = aEndPageRange;
137 return NS_OK;
140 /* attribute boolean printReversed; */
141 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(bool *aPrintReversed)
143 //NS_ENSURE_ARG_POINTER(aPrintReversed);
144 *aPrintReversed = mPrintReversed;
145 return NS_OK;
147 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(bool aPrintReversed)
149 mPrintReversed = aPrintReversed;
150 return NS_OK;
153 /* attribute boolean printInColor; */
154 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(bool *aPrintInColor)
156 //NS_ENSURE_ARG_POINTER(aPrintInColor);
157 *aPrintInColor = mPrintInColor;
158 return NS_OK;
160 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(bool aPrintInColor)
162 mPrintInColor = aPrintInColor;
163 return NS_OK;
166 /* attribute short orientation; */
167 NS_IMETHODIMP nsPrintSettings::GetOrientation(int32_t *aOrientation)
169 NS_ENSURE_ARG_POINTER(aOrientation);
170 *aOrientation = mOrientation;
171 return NS_OK;
173 NS_IMETHODIMP nsPrintSettings::SetOrientation(int32_t aOrientation)
175 mOrientation = aOrientation;
176 return NS_OK;
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);
185 } else {
186 *aColorspace = nullptr;
188 return NS_OK;
190 NS_IMETHODIMP nsPrintSettings::SetColorspace(const char16_t * aColorspace)
192 if (aColorspace) {
193 mColorspace = aColorspace;
194 } else {
195 mColorspace.SetLength(0);
197 return NS_OK;
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);
206 } else {
207 *aResolutionName = nullptr;
209 return NS_OK;
211 NS_IMETHODIMP nsPrintSettings::SetResolutionName(const char16_t * aResolutionName)
213 if (aResolutionName) {
214 mResolutionName = aResolutionName;
215 } else {
216 mResolutionName.SetLength(0);
218 return NS_OK;
221 /* attribute wstring resolution; */
222 NS_IMETHODIMP nsPrintSettings::GetResolution(int32_t *aResolution)
224 NS_ENSURE_ARG_POINTER(aResolution);
225 *aResolution = mResolution;
226 return NS_OK;
228 NS_IMETHODIMP nsPrintSettings::SetResolution(const int32_t aResolution)
230 mResolution = aResolution;
231 return NS_OK;
234 /* attribute wstring duplex; */
235 NS_IMETHODIMP nsPrintSettings::GetDuplex(int32_t *aDuplex)
237 NS_ENSURE_ARG_POINTER(aDuplex);
238 *aDuplex = mDuplex;
239 return NS_OK;
241 NS_IMETHODIMP nsPrintSettings::SetDuplex(const int32_t aDuplex)
243 mDuplex = aDuplex;
244 return NS_OK;
247 /* attribute boolean downloadFonts; */
248 NS_IMETHODIMP nsPrintSettings::GetDownloadFonts(bool *aDownloadFonts)
250 //NS_ENSURE_ARG_POINTER(aDownloadFonts);
251 *aDownloadFonts = mDownloadFonts;
252 return NS_OK;
254 NS_IMETHODIMP nsPrintSettings::SetDownloadFonts(bool aDownloadFonts)
256 mDownloadFonts = aDownloadFonts;
257 return NS_OK;
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);
268 return NS_OK;
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);
279 return NS_OK;
282 /* attribute long numCopies; */
283 NS_IMETHODIMP nsPrintSettings::GetNumCopies(int32_t *aNumCopies)
285 NS_ENSURE_ARG_POINTER(aNumCopies);
286 *aNumCopies = mNumCopies;
287 return NS_OK;
289 NS_IMETHODIMP nsPrintSettings::SetNumCopies(int32_t aNumCopies)
291 mNumCopies = aNumCopies;
292 return NS_OK;
295 /* attribute wstring printCommand; */
296 NS_IMETHODIMP nsPrintSettings::GetPrintCommand(char16_t * *aPrintCommand)
298 //NS_ENSURE_ARG_POINTER(aPrintCommand);
299 *aPrintCommand = ToNewUnicode(mPrintCommand);
300 return NS_OK;
302 NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const char16_t * aPrintCommand)
304 if (aPrintCommand) {
305 mPrintCommand = aPrintCommand;
306 } else {
307 mPrintCommand.SetLength(0);
309 return NS_OK;
312 /* attribute boolean printToFile; */
313 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(bool *aPrintToFile)
315 //NS_ENSURE_ARG_POINTER(aPrintToFile);
316 *aPrintToFile = mPrintToFile;
317 return NS_OK;
319 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(bool aPrintToFile)
321 mPrintToFile = aPrintToFile;
322 return NS_OK;
325 /* attribute wstring toFileName; */
326 NS_IMETHODIMP nsPrintSettings::GetToFileName(char16_t * *aToFileName)
328 //NS_ENSURE_ARG_POINTER(aToFileName);
329 *aToFileName = ToNewUnicode(mToFileName);
330 return NS_OK;
332 NS_IMETHODIMP nsPrintSettings::SetToFileName(const char16_t * aToFileName)
334 if (aToFileName) {
335 mToFileName = aToFileName;
336 } else {
337 mToFileName.SetLength(0);
339 return NS_OK;
342 /* attribute short outputFormat; */
343 NS_IMETHODIMP nsPrintSettings::GetOutputFormat(int16_t *aOutputFormat)
345 NS_ENSURE_ARG_POINTER(aOutputFormat);
346 *aOutputFormat = mOutputFormat;
347 return NS_OK;
349 NS_IMETHODIMP nsPrintSettings::SetOutputFormat(int16_t aOutputFormat)
351 mOutputFormat = aOutputFormat;
352 return NS_OK;
355 /* attribute long printPageDelay; */
356 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(int32_t *aPrintPageDelay)
358 *aPrintPageDelay = mPrintPageDelay;
359 return NS_OK;
361 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(int32_t aPrintPageDelay)
363 mPrintPageDelay = aPrintPageDelay;
364 return NS_OK;
367 /* attribute boolean isInitializedFromPrinter; */
368 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrinter(bool *aIsInitializedFromPrinter)
370 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter);
371 *aIsInitializedFromPrinter = (bool)mIsInitedFromPrinter;
372 return NS_OK;
374 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrinter(bool aIsInitializedFromPrinter)
376 mIsInitedFromPrinter = (bool)aIsInitializedFromPrinter;
377 return NS_OK;
380 /* attribute boolean isInitializedFromPrefs; */
381 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrefs(bool *aInitializedFromPrefs)
383 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs);
384 *aInitializedFromPrefs = (bool)mIsInitedFromPrefs;
385 return NS_OK;
387 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(bool aInitializedFromPrefs)
389 mIsInitedFromPrefs = (bool)aInitializedFromPrefs;
390 return NS_OK;
393 /* attribute boolean persistMarginBoxSettings; */
394 NS_IMETHODIMP nsPrintSettings::GetPersistMarginBoxSettings(bool *aPersistMarginBoxSettings)
396 NS_ENSURE_ARG_POINTER(aPersistMarginBoxSettings);
397 *aPersistMarginBoxSettings = mPersistMarginBoxSettings;
398 return NS_OK;
400 NS_IMETHODIMP nsPrintSettings::SetPersistMarginBoxSettings(bool aPersistMarginBoxSettings)
402 mPersistMarginBoxSettings = aPersistMarginBoxSettings;
403 return NS_OK;
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);
411 return NS_OK;
413 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
415 mMargin.top = NS_INCHES_TO_INT_TWIPS(float(aMarginTop));
416 return NS_OK;
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);
424 return NS_OK;
426 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft)
428 mMargin.left = NS_INCHES_TO_INT_TWIPS(float(aMarginLeft));
429 return NS_OK;
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);
437 return NS_OK;
439 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom)
441 mMargin.bottom = NS_INCHES_TO_INT_TWIPS(float(aMarginBottom));
442 return NS_OK;
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);
450 return NS_OK;
452 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight)
454 mMargin.right = NS_INCHES_TO_INT_TWIPS(float(aMarginRight));
455 return NS_OK;
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);
463 return NS_OK;
465 NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop)
467 mEdge.top = NS_INCHES_TO_INT_TWIPS(float(aEdgeTop));
468 return NS_OK;
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);
476 return NS_OK;
478 NS_IMETHODIMP nsPrintSettings::SetEdgeLeft(double aEdgeLeft)
480 mEdge.left = NS_INCHES_TO_INT_TWIPS(float(aEdgeLeft));
481 return NS_OK;
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);
489 return NS_OK;
491 NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom)
493 mEdge.bottom = NS_INCHES_TO_INT_TWIPS(float(aEdgeBottom));
494 return NS_OK;
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);
502 return NS_OK;
504 NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight)
506 mEdge.right = NS_INCHES_TO_INT_TWIPS(float(aEdgeRight));
507 return NS_OK;
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);
515 return NS_OK;
517 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
519 if (aUnwriteableMarginTop >= 0.0) {
520 mUnwriteableMargin.top = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginTop);
522 return NS_OK;
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);
530 return NS_OK;
532 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
534 if (aUnwriteableMarginLeft >= 0.0) {
535 mUnwriteableMargin.left = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginLeft);
537 return NS_OK;
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);
545 return NS_OK;
547 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
549 if (aUnwriteableMarginBottom >= 0.0) {
550 mUnwriteableMargin.bottom = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginBottom);
552 return NS_OK;
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);
560 return NS_OK;
562 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
564 if (aUnwriteableMarginRight >= 0.0) {
565 mUnwriteableMargin.right = NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginRight);
567 return NS_OK;
570 /* attribute double scaling; */
571 NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling)
573 NS_ENSURE_ARG_POINTER(aScaling);
574 *aScaling = mScaling;
575 return NS_OK;
578 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling)
580 mScaling = aScaling;
581 return NS_OK;
584 /* attribute boolean printBGColors; */
585 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(bool *aPrintBGColors)
587 NS_ENSURE_ARG_POINTER(aPrintBGColors);
588 *aPrintBGColors = mPrintBGColors;
589 return NS_OK;
591 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(bool aPrintBGColors)
593 mPrintBGColors = aPrintBGColors;
594 return NS_OK;
597 /* attribute boolean printBGImages; */
598 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(bool *aPrintBGImages)
600 NS_ENSURE_ARG_POINTER(aPrintBGImages);
601 *aPrintBGImages = mPrintBGImages;
602 return NS_OK;
604 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(bool aPrintBGImages)
606 mPrintBGImages = aPrintBGImages;
607 return NS_OK;
610 /* attribute long printRange; */
611 NS_IMETHODIMP nsPrintSettings::GetPrintRange(int16_t *aPrintRange)
613 NS_ENSURE_ARG_POINTER(aPrintRange);
614 *aPrintRange = mPrintRange;
615 return NS_OK;
617 NS_IMETHODIMP nsPrintSettings::SetPrintRange(int16_t aPrintRange)
619 mPrintRange = aPrintRange;
620 return NS_OK;
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);
629 } else {
630 *aTitle = nullptr;
632 return NS_OK;
634 NS_IMETHODIMP nsPrintSettings::SetTitle(const char16_t * aTitle)
636 if (aTitle) {
637 mTitle = aTitle;
638 } else {
639 mTitle.SetLength(0);
641 return NS_OK;
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);
650 } else {
651 *aDocURL = nullptr;
653 return NS_OK;
655 NS_IMETHODIMP nsPrintSettings::SetDocURL(const char16_t * aDocURL)
657 if (aDocURL) {
658 mURL = aDocURL;
659 } else {
660 mURL.SetLength(0);
662 return NS_OK;
665 /** ---------------------------------------------------
666 * See documentation in nsPrintSettingsImpl.h
667 * @update 1/12/01 rods
669 NS_IMETHODIMP
670 nsPrintSettings::GetPrintOptions(int32_t aType, bool *aTurnOnOff)
672 NS_ENSURE_ARG_POINTER(aTurnOnOff);
673 *aTurnOnOff = mPrintOptions & aType ? true : false;
674 return NS_OK;
676 /** ---------------------------------------------------
677 * See documentation in nsPrintSettingsImpl.h
678 * @update 1/12/01 rods
680 NS_IMETHODIMP
681 nsPrintSettings::SetPrintOptions(int32_t aType, bool aTurnOnOff)
683 if (aTurnOnOff) {
684 mPrintOptions |= aType;
685 } else {
686 mPrintOptions &= ~aType;
688 return NS_OK;
691 /** ---------------------------------------------------
692 * See documentation in nsPrintSettingsImpl.h
693 * @update 1/12/01 rods
695 NS_IMETHODIMP
696 nsPrintSettings::GetPrintOptionsBits(int32_t *aBits)
698 NS_ENSURE_ARG_POINTER(aBits);
699 *aBits = mPrintOptions;
700 return NS_OK;
703 /* attribute wstring docTitle; */
704 nsresult
705 nsPrintSettings::GetMarginStrs(char16_t * *aTitle,
706 nsHeaderFooterEnum aType,
707 int16_t aJust)
709 NS_ENSURE_ARG_POINTER(aTitle);
710 *aTitle = nullptr;
711 if (aType == eHeader) {
712 switch (aJust) {
713 case kJustLeft: *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
714 case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
715 case kJustRight: *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
716 } //switch
717 } else {
718 switch (aJust) {
719 case kJustLeft: *aTitle = ToNewUnicode(mFooterStrs[0]);break;
720 case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
721 case kJustRight: *aTitle = ToNewUnicode(mFooterStrs[2]);break;
722 } //switch
724 return NS_OK;
727 nsresult
728 nsPrintSettings::SetMarginStrs(const char16_t * aTitle,
729 nsHeaderFooterEnum aType,
730 int16_t aJust)
732 NS_ENSURE_ARG_POINTER(aTitle);
733 if (aType == eHeader) {
734 switch (aJust) {
735 case kJustLeft: mHeaderStrs[0] = aTitle;break;
736 case kJustCenter: mHeaderStrs[1] = aTitle;break;
737 case kJustRight: mHeaderStrs[2] = aTitle;break;
738 } //switch
739 } else {
740 switch (aJust) {
741 case kJustLeft: mFooterStrs[0] = aTitle;break;
742 case kJustCenter: mFooterStrs[1] = aTitle;break;
743 case kJustRight: mFooterStrs[2] = aTitle;break;
744 } //switch
746 return NS_OK;
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;
815 return NS_OK;
817 NS_IMETHODIMP nsPrintSettings::SetPrintFrameTypeUsage(int16_t aPrintFrameTypeUsage)
819 mPrintFrameTypeUsage = aPrintFrameTypeUsage;
820 return NS_OK;
823 /* attribute long printFrameType; */
824 NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(int16_t *aPrintFrameType)
826 NS_ENSURE_ARG_POINTER(aPrintFrameType);
827 *aPrintFrameType = (int32_t)mPrintFrameType;
828 return NS_OK;
830 NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(int16_t aPrintFrameType)
832 mPrintFrameType = aPrintFrameType;
833 return NS_OK;
836 /* attribute boolean printSilent; */
837 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(bool *aPrintSilent)
839 NS_ENSURE_ARG_POINTER(aPrintSilent);
840 *aPrintSilent = mPrintSilent;
841 return NS_OK;
843 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(bool aPrintSilent)
845 mPrintSilent = aPrintSilent;
846 return NS_OK;
849 /* attribute boolean shrinkToFit; */
850 NS_IMETHODIMP nsPrintSettings::GetShrinkToFit(bool *aShrinkToFit)
852 NS_ENSURE_ARG_POINTER(aShrinkToFit);
853 *aShrinkToFit = mShrinkToFit;
854 return NS_OK;
856 NS_IMETHODIMP nsPrintSettings::SetShrinkToFit(bool aShrinkToFit)
858 mShrinkToFit = aShrinkToFit;
859 return NS_OK;
862 /* attribute boolean showPrintProgress; */
863 NS_IMETHODIMP nsPrintSettings::GetShowPrintProgress(bool *aShowPrintProgress)
865 NS_ENSURE_ARG_POINTER(aShowPrintProgress);
866 *aShowPrintProgress = mShowPrintProgress;
867 return NS_OK;
869 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress)
871 mShowPrintProgress = aShowPrintProgress;
872 return NS_OK;
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);
881 } else {
882 *aPaperName = nullptr;
884 return NS_OK;
886 NS_IMETHODIMP nsPrintSettings::SetPaperName(const char16_t * aPaperName)
888 if (aPaperName) {
889 mPaperName = aPaperName;
890 } else {
891 mPaperName.SetLength(0);
893 return NS_OK;
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);
902 } else {
903 *aPlexName = nullptr;
905 return NS_OK;
907 NS_IMETHODIMP nsPrintSettings::SetPlexName(const char16_t * aPlexName)
909 if (aPlexName) {
910 mPlexName = aPlexName;
911 } else {
912 mPlexName.SetLength(0);
914 return NS_OK;
917 /* attribute boolean howToEnableFrameUI; */
918 NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI(int16_t *aHowToEnableFrameUI)
920 NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI);
921 *aHowToEnableFrameUI = mHowToEnableFrameUI;
922 return NS_OK;
924 NS_IMETHODIMP nsPrintSettings::SetHowToEnableFrameUI(int16_t aHowToEnableFrameUI)
926 mHowToEnableFrameUI = aHowToEnableFrameUI;
927 return NS_OK;
930 /* attribute long isCancelled; */
931 NS_IMETHODIMP nsPrintSettings::GetIsCancelled(bool *aIsCancelled)
933 NS_ENSURE_ARG_POINTER(aIsCancelled);
934 *aIsCancelled = mIsCancelled;
935 return NS_OK;
937 NS_IMETHODIMP nsPrintSettings::SetIsCancelled(bool aIsCancelled)
939 mIsCancelled = aIsCancelled;
940 return NS_OK;
943 /* attribute double paperWidth; */
944 NS_IMETHODIMP nsPrintSettings::GetPaperWidth(double *aPaperWidth)
946 NS_ENSURE_ARG_POINTER(aPaperWidth);
947 *aPaperWidth = mPaperWidth;
948 return NS_OK;
950 NS_IMETHODIMP nsPrintSettings::SetPaperWidth(double aPaperWidth)
952 mPaperWidth = aPaperWidth;
953 return NS_OK;
956 /* attribute double paperHeight; */
957 NS_IMETHODIMP nsPrintSettings::GetPaperHeight(double *aPaperHeight)
959 NS_ENSURE_ARG_POINTER(aPaperHeight);
960 *aPaperHeight = mPaperHeight;
961 return NS_OK;
963 NS_IMETHODIMP nsPrintSettings::SetPaperHeight(double aPaperHeight)
965 mPaperHeight = aPaperHeight;
966 return NS_OK;
969 /* attribute short PaperSizeUnit; */
970 NS_IMETHODIMP nsPrintSettings::GetPaperSizeUnit(int16_t *aPaperSizeUnit)
972 NS_ENSURE_ARG_POINTER(aPaperSizeUnit);
973 *aPaperSizeUnit = mPaperSizeUnit;
974 return NS_OK;
976 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit)
978 mPaperSizeUnit = aPaperSizeUnit;
979 return NS_OK;
982 /* attribute short PaperSizeType; */
983 NS_IMETHODIMP nsPrintSettings::GetPaperSizeType(int16_t *aPaperSizeType)
985 NS_ENSURE_ARG_POINTER(aPaperSizeType);
986 *aPaperSizeType = mPaperSizeType;
987 return NS_OK;
989 NS_IMETHODIMP nsPrintSettings::SetPaperSizeType(int16_t aPaperSizeType)
991 mPaperSizeType = aPaperSizeType;
992 return NS_OK;
995 /* attribute short PaperData; */
996 NS_IMETHODIMP nsPrintSettings::GetPaperData(int16_t *aPaperData)
998 NS_ENSURE_ARG_POINTER(aPaperData);
999 *aPaperData = mPaperData;
1000 return NS_OK;
1002 NS_IMETHODIMP nsPrintSettings::SetPaperData(int16_t aPaperData)
1004 mPaperData = aPaperData;
1005 return NS_OK;
1008 /** ---------------------------------------------------
1009 * See documentation in nsPrintOptionsImpl.h
1010 * @update 6/21/00 dwc
1011 * @update 1/12/01 rods
1013 NS_IMETHODIMP
1014 nsPrintSettings::SetMarginInTwips(nsIntMargin& aMargin)
1016 mMargin = aMargin;
1017 return NS_OK;
1020 NS_IMETHODIMP
1021 nsPrintSettings::SetEdgeInTwips(nsIntMargin& aEdge)
1023 mEdge = aEdge;
1024 return NS_OK;
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.)
1030 NS_IMETHODIMP
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;
1045 return NS_OK;
1048 /** ---------------------------------------------------
1049 * See documentation in nsPrintOptionsImpl.h
1050 * @update 6/21/00 dwc
1052 NS_IMETHODIMP
1053 nsPrintSettings::GetMarginInTwips(nsIntMargin& aMargin)
1055 aMargin = mMargin;
1056 return NS_OK;
1059 NS_IMETHODIMP
1060 nsPrintSettings::GetEdgeInTwips(nsIntMargin& aEdge)
1062 aEdge = mEdge;
1063 return NS_OK;
1066 NS_IMETHODIMP
1067 nsPrintSettings::GetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin)
1069 aUnwriteableMargin = mUnwriteableMargin;
1070 return NS_OK;
1073 /** ---------------------------------------------------
1074 * Stub - platform-specific implementations can use this function.
1076 NS_IMETHODIMP
1077 nsPrintSettings::SetupSilentPrinting()
1079 return NS_OK;
1082 /** ---------------------------------------------------
1083 * See documentation in nsPrintOptionsImpl.h
1085 NS_IMETHODIMP
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));
1091 } else {
1092 *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth));
1093 *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight));
1095 if (kLandscapeOrientation == mOrientation) {
1096 double temp = *aWidth;
1097 *aWidth = *aHeight;
1098 *aHeight = temp;
1100 return NS_OK;
1103 NS_IMETHODIMP
1104 nsPrintSettings::GetPageRanges(nsTArray<int32_t> &aPages)
1106 aPages.Clear();
1107 return NS_OK;
1110 nsresult
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 (); */
1118 NS_IMETHODIMP
1119 nsPrintSettings::Clone(nsIPrintSettings **_retval)
1121 NS_ENSURE_ARG_POINTER(_retval);
1122 return _Clone(_retval);
1125 /* void assign (in nsIPrintSettings aPS); */
1126 nsresult
1127 nsPrintSettings::_Assign(nsIPrintSettings *aPS)
1129 nsPrintSettings *ps = static_cast<nsPrintSettings*>(aPS);
1130 *this = *ps;
1131 return NS_OK;
1134 /* void assign (in nsIPrintSettings aPS); */
1135 NS_IMETHODIMP
1136 nsPrintSettings::Assign(nsIPrintSettings *aPS)
1138 NS_ENSURE_ARG(aPS);
1139 return _Assign(aPS);
1142 //-------------------------------------------
1143 nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs)
1145 if (this == &rhs) {
1146 return *this;
1149 mStartPageNum = rhs.mStartPageNum;
1150 mEndPageNum = rhs.mEndPageNum;
1151 mMargin = rhs.mMargin;
1152 mEdge = rhs.mEdge;
1153 mUnwriteableMargin = rhs.mUnwriteableMargin;
1154 mScaling = rhs.mScaling;
1155 mPrintBGColors = rhs.mPrintBGColors;
1156 mPrintBGImages = rhs.mPrintBGImages;
1157 mPrintRange = rhs.mPrintRange;
1158 mTitle = rhs.mTitle;
1159 mURL = rhs.mURL;
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];
1190 return *this;