Back to index

lightning-sunbird  0.9+nobinonly
nsPrintSettingsImpl.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsPrintSettingsImpl.h"
00039 #include "nsCoord.h"
00040 #include "nsUnitConversion.h"
00041 #include "nsReadableUtils.h"
00042 #include "nsIPrintSession.h"
00043 
00044 NS_IMPL_ISUPPORTS1(nsPrintSettings, nsIPrintSettings)
00045 
00046 
00050 nsPrintSettings::nsPrintSettings() :
00051   mPrintOptions(0L),
00052   mPrintRange(kRangeAllPages),
00053   mStartPageNum(1),
00054   mEndPageNum(1),
00055   mScaling(1.0),
00056   mPrintBGColors(PR_FALSE),
00057   mPrintBGImages(PR_FALSE),
00058   mPrintFrameTypeUsage(kUseInternalDefault),
00059   mPrintFrameType(kFramesAsIs),
00060   mHowToEnableFrameUI(kFrameEnableNone),
00061   mIsCancelled(PR_FALSE),
00062   mPrintSilent(PR_FALSE),
00063        mPrintPreview(PR_FALSE),
00064   mShrinkToFit(PR_TRUE),
00065   mShowPrintProgress(PR_TRUE),
00066   mPrintPageDelay(500),
00067   mPaperData(0),
00068   mPaperSizeType(kPaperSizeDefined),
00069   mPaperWidth(8.5),
00070   mPaperHeight(11.0),
00071   mPaperSizeUnit(kPaperSizeInches),
00072   mPrintReversed(PR_FALSE),
00073   mPrintInColor(PR_TRUE),
00074   mOrientation(kPortraitOrientation),
00075   mNumCopies(1),
00076   mPrintToFile(PR_FALSE),
00077   mIsInitedFromPrinter(PR_FALSE),
00078   mIsInitedFromPrefs(PR_FALSE)
00079 {
00080 
00081   /* member initializers and constructor code */
00082   nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
00083   mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
00084 
00085   mPrintOptions = kPrintOddPages | kPrintEvenPages;
00086 
00087   mHeaderStrs[0].AssignLiteral("&T");
00088   mHeaderStrs[2].AssignLiteral("&U");
00089 
00090   mFooterStrs[0].AssignLiteral("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
00091   mFooterStrs[2].AssignLiteral("&D");
00092 
00093 }
00094 
00099 nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS)
00100 {
00101   *this = aPS;
00102 }
00103 
00108 nsPrintSettings::~nsPrintSettings()
00109 {
00110 }
00111 
00112 /* [noscript] attribute nsIPrintSession printSession; */
00113 NS_IMETHODIMP nsPrintSettings::GetPrintSession(nsIPrintSession **aPrintSession)
00114 {
00115   NS_ENSURE_ARG_POINTER(aPrintSession);
00116   *aPrintSession = nsnull;
00117   
00118   nsCOMPtr<nsIPrintSession> session = do_QueryReferent(mSession);
00119   if (!session)
00120     return NS_ERROR_NOT_INITIALIZED;
00121   *aPrintSession = session;
00122   NS_ADDREF(*aPrintSession);
00123   return NS_OK;
00124 }
00125 NS_IMETHODIMP nsPrintSettings::SetPrintSession(nsIPrintSession *aPrintSession)
00126 {
00127   // Clearing it by passing NULL is not allowed. That's why we
00128   // use a weak ref so that it doesn't have to be cleared.
00129   NS_ENSURE_ARG(aPrintSession);
00130   
00131   mSession = do_GetWeakReference(aPrintSession);
00132   if (!mSession) {
00133     // This may happen if the implementation of this object does
00134     // not support weak references - programmer error.
00135     NS_ERROR("Could not get a weak reference from aPrintSession");
00136     return NS_ERROR_FAILURE;
00137   }
00138   return NS_OK;
00139 }
00140 
00141 /* attribute long startPageRange; */
00142 NS_IMETHODIMP nsPrintSettings::GetStartPageRange(PRInt32 *aStartPageRange)
00143 {
00144   //NS_ENSURE_ARG_POINTER(aStartPageRange);
00145   *aStartPageRange = mStartPageNum;
00146   return NS_OK;
00147 }
00148 NS_IMETHODIMP nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange)
00149 {
00150   mStartPageNum = aStartPageRange;
00151   return NS_OK;
00152 }
00153 
00154 /* attribute long endPageRange; */
00155 NS_IMETHODIMP nsPrintSettings::GetEndPageRange(PRInt32 *aEndPageRange)
00156 {
00157   //NS_ENSURE_ARG_POINTER(aEndPageRange);
00158   *aEndPageRange = mEndPageNum;
00159   return NS_OK;
00160 }
00161 NS_IMETHODIMP nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange)
00162 {
00163   mEndPageNum = aEndPageRange;
00164   return NS_OK;
00165 }
00166 
00167 /* attribute boolean printReversed; */
00168 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(PRBool *aPrintReversed)
00169 {
00170   //NS_ENSURE_ARG_POINTER(aPrintReversed);
00171   *aPrintReversed = mPrintReversed;
00172   return NS_OK;
00173 }
00174 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(PRBool aPrintReversed)
00175 {
00176   mPrintReversed = aPrintReversed;
00177   return NS_OK;
00178 }
00179 
00180 /* attribute boolean printInColor; */
00181 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(PRBool *aPrintInColor)
00182 {
00183   //NS_ENSURE_ARG_POINTER(aPrintInColor);
00184   *aPrintInColor = mPrintInColor;
00185   return NS_OK;
00186 }
00187 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(PRBool aPrintInColor)
00188 {
00189   mPrintInColor = aPrintInColor;
00190   return NS_OK;
00191 }
00192 
00193 /* attribute short paperSize; */
00194 NS_IMETHODIMP nsPrintSettings::GetPaperSize(PRInt32 *aPaperSize)
00195 {
00196   //NS_ENSURE_ARG_POINTER(aPaperSize);
00197   *aPaperSize = mPaperSize;
00198   return NS_OK;
00199 }
00200 NS_IMETHODIMP nsPrintSettings::SetPaperSize(PRInt32 aPaperSize)
00201 {
00202   mPaperSize = aPaperSize;
00203   return NS_OK;
00204 }
00205 
00206 /* attribute short orientation; */
00207 NS_IMETHODIMP nsPrintSettings::GetOrientation(PRInt32 *aOrientation)
00208 {
00209   NS_ENSURE_ARG_POINTER(aOrientation);
00210   *aOrientation = mOrientation;
00211   return NS_OK;
00212 }
00213 NS_IMETHODIMP nsPrintSettings::SetOrientation(PRInt32 aOrientation)
00214 {
00215   mOrientation = aOrientation;
00216   return NS_OK;
00217 }
00218 
00219 /* attribute wstring colorspace; */
00220 NS_IMETHODIMP nsPrintSettings::GetColorspace(PRUnichar * *aColorspace)
00221 {
00222   NS_ENSURE_ARG_POINTER(aColorspace);
00223   if (!mColorspace.IsEmpty()) {
00224     *aColorspace = ToNewUnicode(mColorspace);
00225   } else {
00226     *aColorspace = nsnull;
00227   }
00228   return NS_OK;
00229 }
00230 NS_IMETHODIMP nsPrintSettings::SetColorspace(const PRUnichar * aColorspace)
00231 {
00232   if (aColorspace) {
00233     mColorspace = aColorspace;
00234   } else {
00235     mColorspace.SetLength(0);
00236   }
00237   return NS_OK;
00238 }
00239 
00240 /* attribute wstring resolutionname; */
00241 NS_IMETHODIMP nsPrintSettings::GetResolutionName(PRUnichar * *aResolutionName)
00242 {
00243   NS_ENSURE_ARG_POINTER(aResolutionName);
00244   if (!mResolutionName.IsEmpty()) {
00245     *aResolutionName = ToNewUnicode(mResolutionName);
00246   } else {
00247     *aResolutionName = nsnull;
00248   }
00249   return NS_OK;
00250 }
00251 NS_IMETHODIMP nsPrintSettings::SetResolutionName(const PRUnichar * aResolutionName)
00252 {
00253   if (aResolutionName) {
00254     mResolutionName = aResolutionName;
00255   } else {
00256     mResolutionName.SetLength(0);
00257   }
00258   return NS_OK;
00259 }
00260 
00261 /* attribute boolean downloadFonts; */
00262 NS_IMETHODIMP nsPrintSettings::GetDownloadFonts(PRBool *aDownloadFonts)
00263 {
00264   //NS_ENSURE_ARG_POINTER(aDownloadFonts);
00265   *aDownloadFonts = mDownloadFonts;
00266   return NS_OK;
00267 }
00268 NS_IMETHODIMP nsPrintSettings::SetDownloadFonts(PRBool aDownloadFonts)
00269 {
00270   mDownloadFonts = aDownloadFonts;
00271   return NS_OK;
00272 }
00273 
00274 /* attribute wstring printer; */
00275 NS_IMETHODIMP nsPrintSettings::GetPrinterName(PRUnichar * *aPrinter)
00276 {
00277    NS_ENSURE_ARG_POINTER(aPrinter);
00278 
00279    *aPrinter = ToNewUnicode(mPrinter);
00280    NS_ENSURE_TRUE(*aPrinter, NS_ERROR_OUT_OF_MEMORY);
00281 
00282    return NS_OK;
00283 }
00284 
00285 NS_IMETHODIMP nsPrintSettings::SetPrinterName(const PRUnichar * aPrinter)
00286 {
00287   if (!aPrinter || !mPrinter.Equals(aPrinter)) {
00288     mIsInitedFromPrinter = PR_FALSE;
00289     mIsInitedFromPrefs   = PR_FALSE;
00290   }
00291 
00292   mPrinter.Assign(aPrinter);
00293   return NS_OK;
00294 }
00295 
00296 /* attribute long numCopies; */
00297 NS_IMETHODIMP nsPrintSettings::GetNumCopies(PRInt32 *aNumCopies)
00298 {
00299   NS_ENSURE_ARG_POINTER(aNumCopies);
00300   *aNumCopies = mNumCopies;
00301   return NS_OK;
00302 }
00303 NS_IMETHODIMP nsPrintSettings::SetNumCopies(PRInt32 aNumCopies)
00304 {
00305   mNumCopies = aNumCopies;
00306   return NS_OK;
00307 }
00308 
00309 /* attribute wstring printCommand; */
00310 NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand)
00311 {
00312   //NS_ENSURE_ARG_POINTER(aPrintCommand);
00313   *aPrintCommand = ToNewUnicode(mPrintCommand);
00314   return NS_OK;
00315 }
00316 NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand)
00317 {
00318   if (aPrintCommand) {
00319     mPrintCommand = aPrintCommand;
00320   } else {
00321     mPrintCommand.SetLength(0);
00322   }
00323   return NS_OK;
00324 }
00325 
00326 /* attribute boolean printToFile; */
00327 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(PRBool *aPrintToFile)
00328 {
00329   //NS_ENSURE_ARG_POINTER(aPrintToFile);
00330   *aPrintToFile = mPrintToFile;
00331   return NS_OK;
00332 }
00333 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(PRBool aPrintToFile)
00334 {
00335   mPrintToFile = aPrintToFile;
00336   return NS_OK;
00337 }
00338 
00339 /* attribute wstring toFileName; */
00340 NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName)
00341 {
00342   //NS_ENSURE_ARG_POINTER(aToFileName);
00343   *aToFileName = ToNewUnicode(mToFileName);
00344   return NS_OK;
00345 }
00346 NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
00347 {
00348   if (aToFileName) {
00349     mToFileName = aToFileName;
00350   } else {
00351     mToFileName.SetLength(0);
00352   }
00353   return NS_OK;
00354 }
00355 
00356 /* attribute long printPageDelay; */
00357 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay)
00358 {
00359   *aPrintPageDelay = mPrintPageDelay;
00360   return NS_OK;
00361 }
00362 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay)
00363 {
00364   mPrintPageDelay = aPrintPageDelay;
00365   return NS_OK;
00366 }
00367 
00368 /* attribute boolean isInitializedFromPrinter; */
00369 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrinter(PRBool *aIsInitializedFromPrinter)
00370 {
00371   NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter);
00372   *aIsInitializedFromPrinter = (PRBool)mIsInitedFromPrinter;
00373   return NS_OK;
00374 }
00375 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrinter(PRBool aIsInitializedFromPrinter)
00376 {
00377   mIsInitedFromPrinter = (PRPackedBool)aIsInitializedFromPrinter;
00378   return NS_OK;
00379 }
00380 
00381 /* attribute boolean isInitializedFromPrefs; */
00382 NS_IMETHODIMP nsPrintSettings::GetIsInitializedFromPrefs(PRBool *aInitializedFromPrefs)
00383 {
00384   NS_ENSURE_ARG_POINTER(aInitializedFromPrefs);
00385   *aInitializedFromPrefs = (PRBool)mIsInitedFromPrefs;
00386   return NS_OK;
00387 }
00388 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(PRBool aInitializedFromPrefs)
00389 {
00390   mIsInitedFromPrefs = (PRPackedBool)aInitializedFromPrefs;
00391   return NS_OK;
00392 }
00393 
00394 /* attribute double marginTop; */
00395 NS_IMETHODIMP nsPrintSettings::GetMarginTop(double *aMarginTop)
00396 {
00397   NS_ENSURE_ARG_POINTER(aMarginTop);
00398   *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
00399   return NS_OK;
00400 }
00401 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
00402 {
00403   mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop));
00404   return NS_OK;
00405 }
00406 
00407 /* attribute double marginLeft; */
00408 NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double *aMarginLeft)
00409 {
00410   NS_ENSURE_ARG_POINTER(aMarginLeft);
00411   *aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
00412   return NS_OK;
00413 }
00414 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft)
00415 {
00416   mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft));
00417   return NS_OK;
00418 }
00419 
00420 /* attribute double marginBottom; */
00421 NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double *aMarginBottom)
00422 {
00423   NS_ENSURE_ARG_POINTER(aMarginBottom);
00424   *aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
00425   return NS_OK;
00426 }
00427 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom)
00428 {
00429   mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom));
00430   return NS_OK;
00431 }
00432 
00433 /* attribute double marginRight; */
00434 NS_IMETHODIMP nsPrintSettings::GetMarginRight(double *aMarginRight)
00435 {
00436   NS_ENSURE_ARG_POINTER(aMarginRight);
00437   *aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
00438   return NS_OK;
00439 }
00440 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight)
00441 {
00442   mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight));
00443   return NS_OK;
00444 }
00445 
00446 /* attribute double scaling; */
00447 NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling)
00448 {
00449   NS_ENSURE_ARG_POINTER(aScaling);
00450   *aScaling = mScaling;
00451   return NS_OK;
00452 }
00453 
00454 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling)
00455 {
00456   mScaling = aScaling;
00457   return NS_OK;
00458 }
00459 
00460 /* attribute boolean printBGColors; */
00461 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(PRBool *aPrintBGColors)
00462 {
00463   NS_ENSURE_ARG_POINTER(aPrintBGColors);
00464   *aPrintBGColors = mPrintBGColors;
00465   return NS_OK;
00466 }
00467 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors)
00468 {
00469   mPrintBGColors = aPrintBGColors;
00470   return NS_OK;
00471 }
00472 
00473 /* attribute boolean printBGImages; */
00474 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(PRBool *aPrintBGImages)
00475 {
00476   NS_ENSURE_ARG_POINTER(aPrintBGImages);
00477   *aPrintBGImages = mPrintBGImages;
00478   return NS_OK;
00479 }
00480 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages)
00481 {
00482   mPrintBGImages = aPrintBGImages;
00483   return NS_OK;
00484 }
00485 
00486 /* attribute long printRange; */
00487 NS_IMETHODIMP nsPrintSettings::GetPrintRange(PRInt16 *aPrintRange)
00488 {
00489   NS_ENSURE_ARG_POINTER(aPrintRange);
00490   *aPrintRange = mPrintRange;
00491   return NS_OK;
00492 }
00493 NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange)
00494 {
00495   mPrintRange = aPrintRange;
00496   return NS_OK;
00497 }
00498 
00499 /* attribute wstring docTitle; */
00500 NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle)
00501 {
00502   NS_ENSURE_ARG_POINTER(aTitle);
00503   if (!mTitle.IsEmpty()) {
00504     *aTitle = ToNewUnicode(mTitle);
00505   } else {
00506     *aTitle = nsnull;
00507   }
00508   return NS_OK;
00509 }
00510 NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle)
00511 {
00512   if (aTitle) {
00513     mTitle = aTitle;
00514   } else {
00515     mTitle.SetLength(0);
00516   }
00517   return NS_OK;
00518 }
00519 
00520 /* attribute wstring docURL; */
00521 NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL)
00522 {
00523   NS_ENSURE_ARG_POINTER(aDocURL);
00524   if (!mURL.IsEmpty()) {
00525     *aDocURL = ToNewUnicode(mURL);
00526   } else {
00527     *aDocURL = nsnull;
00528   }
00529   return NS_OK;
00530 }
00531 NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL)
00532 {
00533   if (aDocURL) {
00534     mURL = aDocURL;
00535   } else {
00536     mURL.SetLength(0);
00537   }
00538   return NS_OK;
00539 }
00540 
00545 NS_IMETHODIMP 
00546 nsPrintSettings::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff)
00547 {
00548   NS_ENSURE_ARG_POINTER(aTurnOnOff);
00549   *aTurnOnOff = mPrintOptions & aType ? PR_TRUE : PR_FALSE;
00550   return NS_OK;
00551 }
00556 NS_IMETHODIMP 
00557 nsPrintSettings::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff)
00558 {
00559   if (aTurnOnOff) {
00560     mPrintOptions |=  aType;
00561   } else {
00562     mPrintOptions &= ~aType;
00563   }
00564   return NS_OK;
00565 }
00566 
00571 NS_IMETHODIMP 
00572 nsPrintSettings::GetPrintOptionsBits(PRInt32 *aBits)
00573 {
00574   NS_ENSURE_ARG_POINTER(aBits);
00575   *aBits = mPrintOptions;
00576   return NS_OK;
00577 }
00578 
00579 /* attribute wstring docTitle; */
00580 nsresult 
00581 nsPrintSettings::GetMarginStrs(PRUnichar * *aTitle, 
00582                               nsHeaderFooterEnum aType, 
00583                               PRInt16 aJust)
00584 {
00585   NS_ENSURE_ARG_POINTER(aTitle);
00586   *aTitle = nsnull;
00587   if (aType == eHeader) {
00588     switch (aJust) {
00589       case kJustLeft:   *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
00590       case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
00591       case kJustRight:  *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
00592     } //switch
00593   } else {
00594     switch (aJust) {
00595       case kJustLeft:   *aTitle = ToNewUnicode(mFooterStrs[0]);break;
00596       case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
00597       case kJustRight:  *aTitle = ToNewUnicode(mFooterStrs[2]);break;
00598     } //switch
00599   }
00600   return NS_OK;
00601 }
00602 
00603 nsresult
00604 nsPrintSettings::SetMarginStrs(const PRUnichar * aTitle, 
00605                               nsHeaderFooterEnum aType, 
00606                               PRInt16 aJust)
00607 {
00608   NS_ENSURE_ARG_POINTER(aTitle);
00609   if (aType == eHeader) {
00610     switch (aJust) {
00611       case kJustLeft:   mHeaderStrs[0] = aTitle;break;
00612       case kJustCenter: mHeaderStrs[1] = aTitle;break;
00613       case kJustRight:  mHeaderStrs[2] = aTitle;break;
00614     } //switch
00615   } else {
00616     switch (aJust) {
00617       case kJustLeft:   mFooterStrs[0] = aTitle;break;
00618       case kJustCenter: mFooterStrs[1] = aTitle;break;
00619       case kJustRight:  mFooterStrs[2] = aTitle;break;
00620     } //switch
00621   }
00622   return NS_OK;
00623 }
00624 
00625 /* attribute wstring Header String Left */
00626 NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(PRUnichar * *aTitle)
00627 {
00628   return GetMarginStrs(aTitle, eHeader, kJustLeft);
00629 }
00630 NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const PRUnichar * aTitle)
00631 {
00632   return SetMarginStrs(aTitle, eHeader, kJustLeft);
00633 }
00634 
00635 /* attribute wstring Header String Center */
00636 NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(PRUnichar * *aTitle)
00637 {
00638   return GetMarginStrs(aTitle, eHeader, kJustCenter);
00639 }
00640 NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const PRUnichar * aTitle)
00641 {
00642   return SetMarginStrs(aTitle, eHeader, kJustCenter);
00643 }
00644 
00645 /* attribute wstring Header String Right */
00646 NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(PRUnichar * *aTitle)
00647 {
00648   return GetMarginStrs(aTitle, eHeader, kJustRight);
00649 }
00650 NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const PRUnichar * aTitle)
00651 {
00652   return SetMarginStrs(aTitle, eHeader, kJustRight);
00653 }
00654 
00655 
00656 /* attribute wstring Footer String Left */
00657 NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(PRUnichar * *aTitle)
00658 {
00659   return GetMarginStrs(aTitle, eFooter, kJustLeft);
00660 }
00661 NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const PRUnichar * aTitle)
00662 {
00663   return SetMarginStrs(aTitle, eFooter, kJustLeft);
00664 }
00665 
00666 /* attribute wstring Footer String Center */
00667 NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(PRUnichar * *aTitle)
00668 {
00669   return GetMarginStrs(aTitle, eFooter, kJustCenter);
00670 }
00671 NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const PRUnichar * aTitle)
00672 {
00673   return SetMarginStrs(aTitle, eFooter, kJustCenter);
00674 }
00675 
00676 /* attribute wstring Footer String Right */
00677 NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(PRUnichar * *aTitle)
00678 {
00679   return GetMarginStrs(aTitle, eFooter, kJustRight);
00680 }
00681 NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const PRUnichar * aTitle)
00682 {
00683   return SetMarginStrs(aTitle, eFooter, kJustRight);
00684 }
00685 
00686 /* attribute short printFrameTypeUsage; */
00687 NS_IMETHODIMP nsPrintSettings::GetPrintFrameTypeUsage(PRInt16 *aPrintFrameTypeUsage)
00688 {
00689   NS_ENSURE_ARG_POINTER(aPrintFrameTypeUsage);
00690   *aPrintFrameTypeUsage = mPrintFrameTypeUsage;
00691   return NS_OK;
00692 }
00693 NS_IMETHODIMP nsPrintSettings::SetPrintFrameTypeUsage(PRInt16 aPrintFrameTypeUsage)
00694 {
00695   mPrintFrameTypeUsage = aPrintFrameTypeUsage;
00696   return NS_OK;
00697 }
00698 
00699 /* attribute long printFrameType; */
00700 NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(PRInt16 *aPrintFrameType)
00701 {
00702   NS_ENSURE_ARG_POINTER(aPrintFrameType);
00703   *aPrintFrameType = (PRInt32)mPrintFrameType;
00704   return NS_OK;
00705 }
00706 NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType)
00707 {
00708   mPrintFrameType = aPrintFrameType;
00709   return NS_OK;
00710 }
00711 
00712 /* attribute boolean printSilent; */
00713 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(PRBool *aPrintSilent)
00714 {
00715   NS_ENSURE_ARG_POINTER(aPrintSilent);
00716   *aPrintSilent = mPrintSilent;
00717   return NS_OK;
00718 }
00719 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(PRBool aPrintSilent)
00720 {
00721   mPrintSilent = aPrintSilent;
00722   return NS_OK;
00723 }
00724 
00725 /* attribute boolean shrinkToFit; */
00726 NS_IMETHODIMP nsPrintSettings::GetShrinkToFit(PRBool *aShrinkToFit)
00727 {
00728   NS_ENSURE_ARG_POINTER(aShrinkToFit);
00729   *aShrinkToFit = mShrinkToFit;
00730   return NS_OK;
00731 }
00732 NS_IMETHODIMP nsPrintSettings::SetShrinkToFit(PRBool aShrinkToFit)
00733 {
00734   mShrinkToFit = aShrinkToFit;
00735   return NS_OK;
00736 }
00737 
00738 /* attribute boolean showPrintProgress; */
00739 NS_IMETHODIMP nsPrintSettings::GetShowPrintProgress(PRBool *aShowPrintProgress)
00740 {
00741   NS_ENSURE_ARG_POINTER(aShowPrintProgress);
00742   *aShowPrintProgress = mShowPrintProgress;
00743   return NS_OK;
00744 }
00745 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(PRBool aShowPrintProgress)
00746 {
00747   mShowPrintProgress = aShowPrintProgress;
00748   return NS_OK;
00749 }
00750 
00751 /* attribute wstring paperName; */
00752 NS_IMETHODIMP nsPrintSettings::GetPaperName(PRUnichar * *aPaperName)
00753 {
00754   NS_ENSURE_ARG_POINTER(aPaperName);
00755   if (!mPaperName.IsEmpty()) {
00756     *aPaperName = ToNewUnicode(mPaperName);
00757   } else {
00758     *aPaperName = nsnull;
00759   }
00760   return NS_OK;
00761 }
00762 NS_IMETHODIMP nsPrintSettings::SetPaperName(const PRUnichar * aPaperName)
00763 {
00764   if (aPaperName) {
00765     mPaperName = aPaperName;
00766   } else {
00767     mPaperName.SetLength(0);
00768   }
00769   return NS_OK;
00770 }
00771 
00772 /* attribute wstring plexName; */
00773 NS_IMETHODIMP nsPrintSettings::GetPlexName(PRUnichar * *aPlexName)
00774 {
00775   NS_ENSURE_ARG_POINTER(aPlexName);
00776   if (!mPlexName.IsEmpty()) {
00777     *aPlexName = ToNewUnicode(mPlexName);
00778   } else {
00779     *aPlexName = nsnull;
00780   }
00781   return NS_OK;
00782 }
00783 NS_IMETHODIMP nsPrintSettings::SetPlexName(const PRUnichar * aPlexName)
00784 {
00785   if (aPlexName) {
00786     mPlexName = aPlexName;
00787   } else {
00788     mPlexName.SetLength(0);
00789   }
00790   return NS_OK;
00791 }
00792 
00793 /* attribute boolean howToEnableFrameUI; */
00794 NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI(PRInt16 *aHowToEnableFrameUI)
00795 {
00796   NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI);
00797   *aHowToEnableFrameUI = (PRInt32)mHowToEnableFrameUI;
00798   return NS_OK;
00799 }
00800 NS_IMETHODIMP nsPrintSettings::SetHowToEnableFrameUI(PRInt16 aHowToEnableFrameUI)
00801 {
00802   mHowToEnableFrameUI = aHowToEnableFrameUI;
00803   return NS_OK;
00804 }
00805 
00806 /* attribute long isCancelled; */
00807 NS_IMETHODIMP nsPrintSettings::GetIsCancelled(PRBool *aIsCancelled)
00808 {
00809   NS_ENSURE_ARG_POINTER(aIsCancelled);
00810   *aIsCancelled = mIsCancelled;
00811   return NS_OK;
00812 }
00813 NS_IMETHODIMP nsPrintSettings::SetIsCancelled(PRBool aIsCancelled)
00814 {
00815   mIsCancelled = aIsCancelled;
00816   return NS_OK;
00817 }
00818 
00819 /* attribute double paperWidth; */
00820 NS_IMETHODIMP nsPrintSettings::GetPaperWidth(double *aPaperWidth)
00821 {
00822   NS_ENSURE_ARG_POINTER(aPaperWidth);
00823   *aPaperWidth = mPaperWidth;
00824   return NS_OK;
00825 }
00826 NS_IMETHODIMP nsPrintSettings::SetPaperWidth(double aPaperWidth)
00827 {
00828   mPaperWidth = aPaperWidth;
00829   return NS_OK;
00830 }
00831 
00832 /* attribute double paperHeight; */
00833 NS_IMETHODIMP nsPrintSettings::GetPaperHeight(double *aPaperHeight)
00834 {
00835   NS_ENSURE_ARG_POINTER(aPaperHeight);
00836   *aPaperHeight = mPaperHeight;
00837   return NS_OK;
00838 }
00839 NS_IMETHODIMP nsPrintSettings::SetPaperHeight(double aPaperHeight)
00840 {
00841   mPaperHeight = aPaperHeight;
00842   return NS_OK;
00843 }
00844 
00845 /* attribute short PaperSizeUnit; */
00846 NS_IMETHODIMP nsPrintSettings::GetPaperSizeUnit(PRInt16 *aPaperSizeUnit)
00847 {
00848   NS_ENSURE_ARG_POINTER(aPaperSizeUnit);
00849   *aPaperSizeUnit = mPaperSizeUnit;
00850   return NS_OK;
00851 }
00852 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(PRInt16 aPaperSizeUnit)
00853 {
00854   mPaperSizeUnit = aPaperSizeUnit;
00855   return NS_OK;
00856 }
00857 
00858 /* attribute short PaperSizeType; */
00859 NS_IMETHODIMP nsPrintSettings::GetPaperSizeType(PRInt16 *aPaperSizeType)
00860 {
00861   NS_ENSURE_ARG_POINTER(aPaperSizeType);
00862   *aPaperSizeType = mPaperSizeType;
00863   return NS_OK;
00864 }
00865 NS_IMETHODIMP nsPrintSettings::SetPaperSizeType(PRInt16 aPaperSizeType)
00866 {
00867   mPaperSizeType = aPaperSizeType;
00868   return NS_OK;
00869 }
00870 
00871 /* attribute short PaperData; */
00872 NS_IMETHODIMP nsPrintSettings::GetPaperData(PRInt16 *aPaperData)
00873 {
00874   NS_ENSURE_ARG_POINTER(aPaperData);
00875   *aPaperData = mPaperData;
00876   return NS_OK;
00877 }
00878 NS_IMETHODIMP nsPrintSettings::SetPaperData(PRInt16 aPaperData)
00879 {
00880   mPaperData = aPaperData;
00881   return NS_OK;
00882 }
00883 
00889 NS_IMETHODIMP 
00890 nsPrintSettings::SetMarginInTwips(nsMargin& aMargin)
00891 {
00892   mMargin = aMargin;
00893   return NS_OK;
00894 }
00895 
00900 NS_IMETHODIMP 
00901 nsPrintSettings::GetMarginInTwips(nsMargin& aMargin)
00902 {
00903   aMargin = mMargin;
00904   return NS_OK;
00905 }
00906 
00911 NS_IMETHODIMP 
00912 nsPrintSettings::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
00913 {
00914   if (mPaperSizeUnit == kPaperSizeInches) {
00915     *aWidth  = NS_INCHES_TO_TWIPS(float(mPaperWidth));
00916     *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight));
00917   } else {
00918     *aWidth  = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth));
00919     *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight));
00920   }
00921   return NS_OK;
00922 }
00923 
00924 nsresult 
00925 nsPrintSettings::_Clone(nsIPrintSettings **_retval)
00926 {
00927   nsPrintSettings* printSettings = new nsPrintSettings(*this);
00928   return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
00929 }
00930 
00931 /* nsIPrintSettings clone (); */
00932 NS_IMETHODIMP 
00933 nsPrintSettings::Clone(nsIPrintSettings **_retval)
00934 {
00935   NS_ENSURE_ARG_POINTER(_retval);
00936   return _Clone(_retval);
00937 }
00938 
00939 /* void assign (in nsIPrintSettings aPS); */
00940 nsresult 
00941 nsPrintSettings::_Assign(nsIPrintSettings *aPS)
00942 {
00943   nsPrintSettings *ps = NS_STATIC_CAST(nsPrintSettings*, aPS);
00944   *this = *ps;
00945   return NS_OK;
00946 }
00947 
00948 /* void assign (in nsIPrintSettings aPS); */
00949 NS_IMETHODIMP 
00950 nsPrintSettings::Assign(nsIPrintSettings *aPS)
00951 {
00952   NS_ENSURE_ARG(aPS);
00953   return _Assign(aPS);
00954 }
00955 
00956 //-------------------------------------------
00957 nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs)
00958 {
00959   if (this == &rhs) {
00960     return *this;
00961   }
00962 
00963   mStartPageNum        = rhs.mStartPageNum;
00964   mEndPageNum          = rhs.mEndPageNum;
00965   mMargin              = rhs.mMargin;
00966   mScaling             = rhs.mScaling;
00967   mPrintBGColors       = rhs.mPrintBGColors;
00968   mPrintBGImages       = rhs.mPrintBGImages;
00969   mPrintRange          = rhs.mPrintRange;
00970   mTitle               = rhs.mTitle;
00971   mURL                 = rhs.mURL;
00972   mHowToEnableFrameUI  = rhs.mHowToEnableFrameUI;
00973   mIsCancelled         = rhs.mIsCancelled;
00974   mPrintFrameTypeUsage = rhs.mPrintFrameTypeUsage;
00975   mPrintFrameType      = rhs.mPrintFrameType;
00976   mPrintSilent         = rhs.mPrintSilent;
00977   mShrinkToFit         = rhs.mShrinkToFit;
00978   mShowPrintProgress   = rhs.mShowPrintProgress;
00979   mPaperName           = rhs.mPaperName;
00980   mPlexName            = rhs.mPlexName;
00981   mPaperSizeType       = rhs.mPaperSizeType;
00982   mPaperData           = rhs.mPaperData;
00983   mPaperWidth          = rhs.mPaperWidth;
00984   mPaperHeight         = rhs.mPaperHeight;
00985   mPaperSizeUnit       = rhs.mPaperSizeUnit;
00986   mPrintReversed       = rhs.mPrintReversed;
00987   mPrintInColor        = rhs.mPrintInColor;
00988   mPaperSize           = rhs.mPaperSize;
00989   mOrientation         = rhs.mOrientation;
00990   mPrintCommand        = rhs.mPrintCommand;
00991   mNumCopies           = rhs.mNumCopies;
00992   mPrinter             = rhs.mPrinter;
00993   mPrintToFile         = rhs.mPrintToFile;
00994   mToFileName          = rhs.mToFileName;
00995   mPrintPageDelay      = rhs.mPrintPageDelay;
00996 
00997   for (PRInt32 i=0;i<NUM_HEAD_FOOT;i++) {
00998     mHeaderStrs[i] = rhs.mHeaderStrs[i];
00999     mFooterStrs[i] = rhs.mFooterStrs[i];
01000   }
01001 
01002   return *this;
01003 }
01004