Add copy of .ttf font with .eot extension for testing
[wine-gecko.git] / widget / src / xpwidgets / nsPrintSettingsImpl.cpp
blob5487d5a1cc3458262675ca7a33090d1613126f92
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
13 * License.
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.
22 * Contributor(s):
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"
39 #include "nsCoord.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
49 * @update 6/21/00 dwc
51 nsPrintSettings::nsPrintSettings() :
52 mPrintOptions(0L),
53 mPrintRange(kRangeAllPages),
54 mStartPageNum(1),
55 mEndPageNum(1),
56 mScaling(1.0),
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),
67 mPrintPageDelay(500),
68 mPaperData(0),
69 mPaperSizeType(kPaperSizeDefined),
70 mPaperWidth(8.5),
71 mPaperHeight(11.0),
72 mPaperSizeUnit(kPaperSizeInches),
73 mPrintReversed(PR_FALSE),
74 mPrintInColor(PR_TRUE),
75 mOrientation(kPortraitOrientation),
76 mDownloadFonts(PR_FALSE),
77 mNumCopies(1),
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)
106 *this = 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);
124 if (!session)
125 return NS_ERROR_NOT_INITIALIZED;
126 *aPrintSession = session;
127 NS_ADDREF(*aPrintSession);
128 return NS_OK;
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);
137 if (!mSession) {
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;
143 return NS_OK;
146 /* attribute long startPageRange; */
147 NS_IMETHODIMP nsPrintSettings::GetStartPageRange(PRInt32 *aStartPageRange)
149 //NS_ENSURE_ARG_POINTER(aStartPageRange);
150 *aStartPageRange = mStartPageNum;
151 return NS_OK;
153 NS_IMETHODIMP nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange)
155 mStartPageNum = aStartPageRange;
156 return NS_OK;
159 /* attribute long endPageRange; */
160 NS_IMETHODIMP nsPrintSettings::GetEndPageRange(PRInt32 *aEndPageRange)
162 //NS_ENSURE_ARG_POINTER(aEndPageRange);
163 *aEndPageRange = mEndPageNum;
164 return NS_OK;
166 NS_IMETHODIMP nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange)
168 mEndPageNum = aEndPageRange;
169 return NS_OK;
172 /* attribute boolean printReversed; */
173 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(PRBool *aPrintReversed)
175 //NS_ENSURE_ARG_POINTER(aPrintReversed);
176 *aPrintReversed = mPrintReversed;
177 return NS_OK;
179 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(PRBool aPrintReversed)
181 mPrintReversed = aPrintReversed;
182 return NS_OK;
185 /* attribute boolean printInColor; */
186 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(PRBool *aPrintInColor)
188 //NS_ENSURE_ARG_POINTER(aPrintInColor);
189 *aPrintInColor = mPrintInColor;
190 return NS_OK;
192 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(PRBool aPrintInColor)
194 mPrintInColor = aPrintInColor;
195 return NS_OK;
198 /* attribute short orientation; */
199 NS_IMETHODIMP nsPrintSettings::GetOrientation(PRInt32 *aOrientation)
201 NS_ENSURE_ARG_POINTER(aOrientation);
202 *aOrientation = mOrientation;
203 return NS_OK;
205 NS_IMETHODIMP nsPrintSettings::SetOrientation(PRInt32 aOrientation)
207 mOrientation = aOrientation;
208 return NS_OK;
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);
217 } else {
218 *aColorspace = nsnull;
220 return NS_OK;
222 NS_IMETHODIMP nsPrintSettings::SetColorspace(const PRUnichar * aColorspace)
224 if (aColorspace) {
225 mColorspace = aColorspace;
226 } else {
227 mColorspace.SetLength(0);
229 return NS_OK;
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);
238 } else {
239 *aResolutionName = nsnull;
241 return NS_OK;
243 NS_IMETHODIMP nsPrintSettings::SetResolutionName(const PRUnichar * aResolutionName)
245 if (aResolutionName) {
246 mResolutionName = aResolutionName;
247 } else {
248 mResolutionName.SetLength(0);
250 return NS_OK;
253 /* attribute boolean downloadFonts; */
254 NS_IMETHODIMP nsPrintSettings::GetDownloadFonts(PRBool *aDownloadFonts)
256 //NS_ENSURE_ARG_POINTER(aDownloadFonts);
257 *aDownloadFonts = mDownloadFonts;
258 return NS_OK;
260 NS_IMETHODIMP nsPrintSettings::SetDownloadFonts(PRBool aDownloadFonts)
262 mDownloadFonts = aDownloadFonts;
263 return NS_OK;
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);
274 return NS_OK;
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);
285 return NS_OK;
288 /* attribute long numCopies; */
289 NS_IMETHODIMP nsPrintSettings::GetNumCopies(PRInt32 *aNumCopies)
291 NS_ENSURE_ARG_POINTER(aNumCopies);
292 *aNumCopies = mNumCopies;
293 return NS_OK;
295 NS_IMETHODIMP nsPrintSettings::SetNumCopies(PRInt32 aNumCopies)
297 mNumCopies = aNumCopies;
298 return NS_OK;
301 /* attribute wstring printCommand; */
302 NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand)
304 //NS_ENSURE_ARG_POINTER(aPrintCommand);
305 *aPrintCommand = ToNewUnicode(mPrintCommand);
306 return NS_OK;
308 NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand)
310 if (aPrintCommand) {
311 mPrintCommand = aPrintCommand;
312 } else {
313 mPrintCommand.SetLength(0);
315 return NS_OK;
318 /* attribute boolean printToFile; */
319 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(PRBool *aPrintToFile)
321 //NS_ENSURE_ARG_POINTER(aPrintToFile);
322 *aPrintToFile = mPrintToFile;
323 return NS_OK;
325 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(PRBool aPrintToFile)
327 mPrintToFile = aPrintToFile;
328 return NS_OK;
331 /* attribute wstring toFileName; */
332 NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName)
334 //NS_ENSURE_ARG_POINTER(aToFileName);
335 *aToFileName = ToNewUnicode(mToFileName);
336 return NS_OK;
338 NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
340 if (aToFileName) {
341 mToFileName = aToFileName;
342 } else {
343 mToFileName.SetLength(0);
345 return NS_OK;
348 /* attribute short outputFormat; */
349 NS_IMETHODIMP nsPrintSettings::GetOutputFormat(PRInt16 *aOutputFormat)
351 NS_ENSURE_ARG_POINTER(aOutputFormat);
352 *aOutputFormat = mOutputFormat;
353 return NS_OK;
355 NS_IMETHODIMP nsPrintSettings::SetOutputFormat(PRInt16 aOutputFormat)
357 mOutputFormat = aOutputFormat;
358 return NS_OK;
361 /* attribute long printPageDelay; */
362 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay)
364 *aPrintPageDelay = mPrintPageDelay;
365 return NS_OK;
367 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay)
369 mPrintPageDelay = aPrintPageDelay;
370 return NS_OK;
373 /* attribute boolean isInitializedFromPrinter; */
374 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrinter(PRBool *aIsInitializedFromPrinter)
376 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter);
377 *aIsInitializedFromPrinter = (PRBool)mIsInitedFromPrinter;
378 return NS_OK;
380 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrinter(PRBool aIsInitializedFromPrinter)
382 mIsInitedFromPrinter = (PRPackedBool)aIsInitializedFromPrinter;
383 return NS_OK;
386 /* attribute boolean isInitializedFromPrefs; */
387 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrefs(PRBool *aInitializedFromPrefs)
389 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs);
390 *aInitializedFromPrefs = (PRBool)mIsInitedFromPrefs;
391 return NS_OK;
393 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(PRBool aInitializedFromPrefs)
395 mIsInitedFromPrefs = (PRPackedBool)aInitializedFromPrefs;
396 return NS_OK;
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);
404 return NS_OK;
406 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
408 mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop));
409 return NS_OK;
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);
417 return NS_OK;
419 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft)
421 mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft));
422 return NS_OK;
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);
430 return NS_OK;
432 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom)
434 mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom));
435 return NS_OK;
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);
443 return NS_OK;
445 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight)
447 mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight));
448 return NS_OK;
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);
456 return NS_OK;
458 NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop)
460 mEdge.top = NS_INCHES_TO_TWIPS(float(aEdgeTop));
461 return NS_OK;
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);
469 return NS_OK;
471 NS_IMETHODIMP nsPrintSettings::SetEdgeLeft(double aEdgeLeft)
473 mEdge.left = NS_INCHES_TO_TWIPS(float(aEdgeLeft));
474 return NS_OK;
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);
482 return NS_OK;
484 NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom)
486 mEdge.bottom = NS_INCHES_TO_TWIPS(float(aEdgeBottom));
487 return NS_OK;
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);
495 return NS_OK;
497 NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight)
499 mEdge.right = NS_INCHES_TO_TWIPS(float(aEdgeRight));
500 return NS_OK;
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);
508 return NS_OK;
510 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
512 if (aUnwriteableMarginTop >= 0.0) {
513 mUnwriteableMargin.top = NS_INCHES_TO_TWIPS(aUnwriteableMarginTop);
515 return NS_OK;
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);
523 return NS_OK;
525 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
527 if (aUnwriteableMarginLeft >= 0.0) {
528 mUnwriteableMargin.left = NS_INCHES_TO_TWIPS(aUnwriteableMarginLeft);
530 return NS_OK;
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);
538 return NS_OK;
540 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
542 if (aUnwriteableMarginBottom >= 0.0) {
543 mUnwriteableMargin.bottom = NS_INCHES_TO_TWIPS(aUnwriteableMarginBottom);
545 return NS_OK;
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);
553 return NS_OK;
555 NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
557 if (aUnwriteableMarginRight >= 0.0) {
558 mUnwriteableMargin.right = NS_INCHES_TO_TWIPS(aUnwriteableMarginRight);
560 return NS_OK;
563 /* attribute double scaling; */
564 NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling)
566 NS_ENSURE_ARG_POINTER(aScaling);
567 *aScaling = mScaling;
568 return NS_OK;
571 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling)
573 mScaling = aScaling;
574 return NS_OK;
577 /* attribute boolean printBGColors; */
578 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(PRBool *aPrintBGColors)
580 NS_ENSURE_ARG_POINTER(aPrintBGColors);
581 *aPrintBGColors = mPrintBGColors;
582 return NS_OK;
584 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors)
586 mPrintBGColors = aPrintBGColors;
587 return NS_OK;
590 /* attribute boolean printBGImages; */
591 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(PRBool *aPrintBGImages)
593 NS_ENSURE_ARG_POINTER(aPrintBGImages);
594 *aPrintBGImages = mPrintBGImages;
595 return NS_OK;
597 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages)
599 mPrintBGImages = aPrintBGImages;
600 return NS_OK;
603 /* attribute long printRange; */
604 NS_IMETHODIMP nsPrintSettings::GetPrintRange(PRInt16 *aPrintRange)
606 NS_ENSURE_ARG_POINTER(aPrintRange);
607 *aPrintRange = mPrintRange;
608 return NS_OK;
610 NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange)
612 mPrintRange = aPrintRange;
613 return NS_OK;
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);
622 } else {
623 *aTitle = nsnull;
625 return NS_OK;
627 NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle)
629 if (aTitle) {
630 mTitle = aTitle;
631 } else {
632 mTitle.SetLength(0);
634 return NS_OK;
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);
643 } else {
644 *aDocURL = nsnull;
646 return NS_OK;
648 NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL)
650 if (aDocURL) {
651 mURL = aDocURL;
652 } else {
653 mURL.SetLength(0);
655 return NS_OK;
658 /** ---------------------------------------------------
659 * See documentation in nsPrintSettingsImpl.h
660 * @update 1/12/01 rods
662 NS_IMETHODIMP
663 nsPrintSettings::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff)
665 NS_ENSURE_ARG_POINTER(aTurnOnOff);
666 *aTurnOnOff = mPrintOptions & aType ? PR_TRUE : PR_FALSE;
667 return NS_OK;
669 /** ---------------------------------------------------
670 * See documentation in nsPrintSettingsImpl.h
671 * @update 1/12/01 rods
673 NS_IMETHODIMP
674 nsPrintSettings::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff)
676 if (aTurnOnOff) {
677 mPrintOptions |= aType;
678 } else {
679 mPrintOptions &= ~aType;
681 return NS_OK;
684 /** ---------------------------------------------------
685 * See documentation in nsPrintSettingsImpl.h
686 * @update 1/12/01 rods
688 NS_IMETHODIMP
689 nsPrintSettings::GetPrintOptionsBits(PRInt32 *aBits)
691 NS_ENSURE_ARG_POINTER(aBits);
692 *aBits = mPrintOptions;
693 return NS_OK;
696 /* attribute wstring docTitle; */
697 nsresult
698 nsPrintSettings::GetMarginStrs(PRUnichar * *aTitle,
699 nsHeaderFooterEnum aType,
700 PRInt16 aJust)
702 NS_ENSURE_ARG_POINTER(aTitle);
703 *aTitle = nsnull;
704 if (aType == eHeader) {
705 switch (aJust) {
706 case kJustLeft: *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
707 case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
708 case kJustRight: *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
709 } //switch
710 } else {
711 switch (aJust) {
712 case kJustLeft: *aTitle = ToNewUnicode(mFooterStrs[0]);break;
713 case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
714 case kJustRight: *aTitle = ToNewUnicode(mFooterStrs[2]);break;
715 } //switch
717 return NS_OK;
720 nsresult
721 nsPrintSettings::SetMarginStrs(const PRUnichar * aTitle,
722 nsHeaderFooterEnum aType,
723 PRInt16 aJust)
725 NS_ENSURE_ARG_POINTER(aTitle);
726 if (aType == eHeader) {
727 switch (aJust) {
728 case kJustLeft: mHeaderStrs[0] = aTitle;break;
729 case kJustCenter: mHeaderStrs[1] = aTitle;break;
730 case kJustRight: mHeaderStrs[2] = aTitle;break;
731 } //switch
732 } else {
733 switch (aJust) {
734 case kJustLeft: mFooterStrs[0] = aTitle;break;
735 case kJustCenter: mFooterStrs[1] = aTitle;break;
736 case kJustRight: mFooterStrs[2] = aTitle;break;
737 } //switch
739 return NS_OK;
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;
808 return NS_OK;
810 NS_IMETHODIMP nsPrintSettings::SetPrintFrameTypeUsage(PRInt16 aPrintFrameTypeUsage)
812 mPrintFrameTypeUsage = aPrintFrameTypeUsage;
813 return NS_OK;
816 /* attribute long printFrameType; */
817 NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(PRInt16 *aPrintFrameType)
819 NS_ENSURE_ARG_POINTER(aPrintFrameType);
820 *aPrintFrameType = (PRInt32)mPrintFrameType;
821 return NS_OK;
823 NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType)
825 mPrintFrameType = aPrintFrameType;
826 return NS_OK;
829 /* attribute boolean printSilent; */
830 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(PRBool *aPrintSilent)
832 NS_ENSURE_ARG_POINTER(aPrintSilent);
833 *aPrintSilent = mPrintSilent;
834 return NS_OK;
836 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(PRBool aPrintSilent)
838 mPrintSilent = aPrintSilent;
839 return NS_OK;
842 /* attribute boolean shrinkToFit; */
843 NS_IMETHODIMP nsPrintSettings::GetShrinkToFit(PRBool *aShrinkToFit)
845 NS_ENSURE_ARG_POINTER(aShrinkToFit);
846 *aShrinkToFit = mShrinkToFit;
847 return NS_OK;
849 NS_IMETHODIMP nsPrintSettings::SetShrinkToFit(PRBool aShrinkToFit)
851 mShrinkToFit = aShrinkToFit;
852 return NS_OK;
855 /* attribute boolean showPrintProgress; */
856 NS_IMETHODIMP nsPrintSettings::GetShowPrintProgress(PRBool *aShowPrintProgress)
858 NS_ENSURE_ARG_POINTER(aShowPrintProgress);
859 *aShowPrintProgress = mShowPrintProgress;
860 return NS_OK;
862 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(PRBool aShowPrintProgress)
864 mShowPrintProgress = aShowPrintProgress;
865 return NS_OK;
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);
874 } else {
875 *aPaperName = nsnull;
877 return NS_OK;
879 NS_IMETHODIMP nsPrintSettings::SetPaperName(const PRUnichar * aPaperName)
881 if (aPaperName) {
882 mPaperName = aPaperName;
883 } else {
884 mPaperName.SetLength(0);
886 return NS_OK;
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);
895 } else {
896 *aPlexName = nsnull;
898 return NS_OK;
900 NS_IMETHODIMP nsPrintSettings::SetPlexName(const PRUnichar * aPlexName)
902 if (aPlexName) {
903 mPlexName = aPlexName;
904 } else {
905 mPlexName.SetLength(0);
907 return NS_OK;
910 /* attribute boolean howToEnableFrameUI; */
911 NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI(PRInt16 *aHowToEnableFrameUI)
913 NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI);
914 *aHowToEnableFrameUI = (PRInt32)mHowToEnableFrameUI;
915 return NS_OK;
917 NS_IMETHODIMP nsPrintSettings::SetHowToEnableFrameUI(PRInt16 aHowToEnableFrameUI)
919 mHowToEnableFrameUI = aHowToEnableFrameUI;
920 return NS_OK;
923 /* attribute long isCancelled; */
924 NS_IMETHODIMP nsPrintSettings::GetIsCancelled(PRBool *aIsCancelled)
926 NS_ENSURE_ARG_POINTER(aIsCancelled);
927 *aIsCancelled = mIsCancelled;
928 return NS_OK;
930 NS_IMETHODIMP nsPrintSettings::SetIsCancelled(PRBool aIsCancelled)
932 mIsCancelled = aIsCancelled;
933 return NS_OK;
936 /* attribute double paperWidth; */
937 NS_IMETHODIMP nsPrintSettings::GetPaperWidth(double *aPaperWidth)
939 NS_ENSURE_ARG_POINTER(aPaperWidth);
940 *aPaperWidth = mPaperWidth;
941 return NS_OK;
943 NS_IMETHODIMP nsPrintSettings::SetPaperWidth(double aPaperWidth)
945 mPaperWidth = aPaperWidth;
946 return NS_OK;
949 /* attribute double paperHeight; */
950 NS_IMETHODIMP nsPrintSettings::GetPaperHeight(double *aPaperHeight)
952 NS_ENSURE_ARG_POINTER(aPaperHeight);
953 *aPaperHeight = mPaperHeight;
954 return NS_OK;
956 NS_IMETHODIMP nsPrintSettings::SetPaperHeight(double aPaperHeight)
958 mPaperHeight = aPaperHeight;
959 return NS_OK;
962 /* attribute short PaperSizeUnit; */
963 NS_IMETHODIMP nsPrintSettings::GetPaperSizeUnit(PRInt16 *aPaperSizeUnit)
965 NS_ENSURE_ARG_POINTER(aPaperSizeUnit);
966 *aPaperSizeUnit = mPaperSizeUnit;
967 return NS_OK;
969 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(PRInt16 aPaperSizeUnit)
971 mPaperSizeUnit = aPaperSizeUnit;
972 return NS_OK;
975 /* attribute short PaperSizeType; */
976 NS_IMETHODIMP nsPrintSettings::GetPaperSizeType(PRInt16 *aPaperSizeType)
978 NS_ENSURE_ARG_POINTER(aPaperSizeType);
979 *aPaperSizeType = mPaperSizeType;
980 return NS_OK;
982 NS_IMETHODIMP nsPrintSettings::SetPaperSizeType(PRInt16 aPaperSizeType)
984 mPaperSizeType = aPaperSizeType;
985 return NS_OK;
988 /* attribute short PaperData; */
989 NS_IMETHODIMP nsPrintSettings::GetPaperData(PRInt16 *aPaperData)
991 NS_ENSURE_ARG_POINTER(aPaperData);
992 *aPaperData = mPaperData;
993 return NS_OK;
995 NS_IMETHODIMP nsPrintSettings::SetPaperData(PRInt16 aPaperData)
997 mPaperData = aPaperData;
998 return NS_OK;
1001 /** ---------------------------------------------------
1002 * See documentation in nsPrintOptionsImpl.h
1003 * @update 6/21/00 dwc
1004 * @update 1/12/01 rods
1006 NS_IMETHODIMP
1007 nsPrintSettings::SetMarginInTwips(nsMargin& aMargin)
1009 mMargin = aMargin;
1010 return NS_OK;
1013 NS_IMETHODIMP
1014 nsPrintSettings::SetEdgeInTwips(nsMargin& aEdge)
1016 mEdge = aEdge;
1017 return NS_OK;
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.)
1023 NS_IMETHODIMP
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;
1038 return NS_OK;
1041 /** ---------------------------------------------------
1042 * See documentation in nsPrintOptionsImpl.h
1043 * @update 6/21/00 dwc
1045 NS_IMETHODIMP
1046 nsPrintSettings::GetMarginInTwips(nsMargin& aMargin)
1048 aMargin = mMargin;
1049 return NS_OK;
1052 NS_IMETHODIMP
1053 nsPrintSettings::GetEdgeInTwips(nsMargin& aEdge)
1055 aEdge = mEdge;
1056 return NS_OK;
1059 NS_IMETHODIMP
1060 nsPrintSettings::GetUnwriteableMarginInTwips(nsMargin& aUnwriteableMargin)
1062 aUnwriteableMargin = mUnwriteableMargin;
1063 return NS_OK;
1066 /** ---------------------------------------------------
1067 * Stub - platform-specific implementations can use this function.
1069 NS_IMETHODIMP
1070 nsPrintSettings::SetupSilentPrinting()
1072 return NS_OK;
1075 /** ---------------------------------------------------
1076 * See documentation in nsPrintOptionsImpl.h
1078 NS_IMETHODIMP
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));
1084 } else {
1085 *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth));
1086 *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight));
1088 if (kLandscapeOrientation == mOrientation) {
1089 double temp = *aWidth;
1090 *aWidth = *aHeight;
1091 *aHeight = temp;
1093 return NS_OK;
1096 nsresult
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 (); */
1104 NS_IMETHODIMP
1105 nsPrintSettings::Clone(nsIPrintSettings **_retval)
1107 NS_ENSURE_ARG_POINTER(_retval);
1108 return _Clone(_retval);
1111 /* void assign (in nsIPrintSettings aPS); */
1112 nsresult
1113 nsPrintSettings::_Assign(nsIPrintSettings *aPS)
1115 nsPrintSettings *ps = static_cast<nsPrintSettings*>(aPS);
1116 *this = *ps;
1117 return NS_OK;
1120 /* void assign (in nsIPrintSettings aPS); */
1121 NS_IMETHODIMP
1122 nsPrintSettings::Assign(nsIPrintSettings *aPS)
1124 NS_ENSURE_ARG(aPS);
1125 return _Assign(aPS);
1128 //-------------------------------------------
1129 nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs)
1131 if (this == &rhs) {
1132 return *this;
1135 mStartPageNum = rhs.mStartPageNum;
1136 mEndPageNum = rhs.mEndPageNum;
1137 mMargin = rhs.mMargin;
1138 mEdge = rhs.mEdge;
1139 mUnwriteableMargin = rhs.mUnwriteableMargin;
1140 mScaling = rhs.mScaling;
1141 mPrintBGColors = rhs.mPrintBGColors;
1142 mPrintBGImages = rhs.mPrintBGImages;
1143 mPrintRange = rhs.mPrintRange;
1144 mTitle = rhs.mTitle;
1145 mURL = rhs.mURL;
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];
1176 return *this;