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 the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 
00043 // For Prefs
00044 #include "nsIPref.h"
00045 #include "nsIServiceManager.h"
00046 
00047 NS_IMPL_ISUPPORTS1(nsPrintSettings, nsIPrintSettings)
00048 
00049 
00053 nsPrintSettings::nsPrintSettings() :
00054   mPrintRange(kRangeAllPages),
00055   mStartPageNum(1),
00056   mEndPageNum(1),
00057   mScaling(1.0),
00058   mPrintBGColors(PR_FALSE),
00059   mPrintBGImages(PR_FALSE),
00060   mPrintOptions(0L),
00061   mPrintReversed(PR_FALSE),
00062   mPrintInColor(PR_TRUE),
00063   mPaperSize(kLetterPaperSize),
00064   mOrientation(kPortraitOrientation),
00065   mPrintToFile(PR_FALSE),
00066   mPrintFrameType(kFramesAsIs),
00067   mPrintPageDelay(500),
00068   mPrintSilent(PR_FALSE)
00069 {
00070   NS_INIT_ISUPPORTS();
00071 
00072   /* member initializers and constructor code */
00073   nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
00074   mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
00075 
00076   mPrintOptions = kOptPrintOddPages | kOptPrintEvenPages;
00077 
00078   mHeaderStrs[0].AssignLiteral("&T");
00079   mHeaderStrs[2].AssignLiteral("&U");
00080 
00081   mFooterStrs[0].AssignLiteral("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
00082   mFooterStrs[2].AssignLiteral("&D");
00083 
00084 }
00085 
00090 nsPrintSettings::~nsPrintSettings()
00091 {
00092 }
00093 
00094 
00095 /* attribute long startPageRange; */
00096 NS_IMETHODIMP nsPrintSettings::GetStartPageRange(PRInt32 *aStartPageRange)
00097 {
00098   //NS_ENSURE_ARG_POINTER(aStartPageRange);
00099   *aStartPageRange = mStartPageNum;
00100   return NS_OK;
00101 }
00102 NS_IMETHODIMP nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange)
00103 {
00104   mStartPageNum = aStartPageRange;
00105   return NS_OK;
00106 }
00107 
00108 /* attribute long endPageRange; */
00109 NS_IMETHODIMP nsPrintSettings::GetEndPageRange(PRInt32 *aEndPageRange)
00110 {
00111   //NS_ENSURE_ARG_POINTER(aEndPageRange);
00112   *aEndPageRange = mEndPageNum;
00113   return NS_OK;
00114 }
00115 NS_IMETHODIMP nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange)
00116 {
00117   mEndPageNum = aEndPageRange;
00118   return NS_OK;
00119 }
00120 
00121 /* attribute boolean printReversed; */
00122 NS_IMETHODIMP nsPrintSettings::GetPrintReversed(PRBool *aPrintReversed)
00123 {
00124   //NS_ENSURE_ARG_POINTER(aPrintReversed);
00125   *aPrintReversed = mPrintReversed;
00126   return NS_OK;
00127 }
00128 NS_IMETHODIMP nsPrintSettings::SetPrintReversed(PRBool aPrintReversed)
00129 {
00130   mPrintReversed = aPrintReversed;
00131   return NS_OK;
00132 }
00133 
00134 /* attribute boolean printInColor; */
00135 NS_IMETHODIMP nsPrintSettings::GetPrintInColor(PRBool *aPrintInColor)
00136 {
00137   //NS_ENSURE_ARG_POINTER(aPrintInColor);
00138   *aPrintInColor = mPrintInColor;
00139   return NS_OK;
00140 }
00141 NS_IMETHODIMP nsPrintSettings::SetPrintInColor(PRBool aPrintInColor)
00142 {
00143   mPrintInColor = aPrintInColor;
00144   return NS_OK;
00145 }
00146 
00147 /* attribute short paperSize; */
00148 NS_IMETHODIMP nsPrintSettings::GetPaperSize(PRInt32 *aPaperSize)
00149 {
00150   //NS_ENSURE_ARG_POINTER(aPaperSize);
00151   *aPaperSize = mPaperSize;
00152   return NS_OK;
00153 }
00154 NS_IMETHODIMP nsPrintSettings::SetPaperSize(PRInt32 aPaperSize)
00155 {
00156   mPaperSize = aPaperSize;
00157   return NS_OK;
00158 }
00159 
00160 /* attribute short orientation; */
00161 NS_IMETHODIMP nsPrintSettings::GetOrientation(PRInt32 *aOrientation)
00162 {
00163   //NS_ENSURE_ARG_POINTER(aOrientation);
00164   *aOrientation = mOrientation;
00165   return NS_OK;
00166 }
00167 NS_IMETHODIMP nsPrintSettings::SetOrientation(PRInt32 aOrientation)
00168 {
00169   mOrientation = aOrientation;
00170   return NS_OK;
00171 }
00172 
00173 /* attribute wstring printCommand; */
00174 NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand)
00175 {
00176   //NS_ENSURE_ARG_POINTER(aPrintCommand);
00177   *aPrintCommand = ToNewUnicode(mPrintCommand);
00178   return NS_OK;
00179 }
00180 NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand)
00181 {
00182   mPrintCommand = aPrintCommand;
00183   return NS_OK;
00184 }
00185 
00186 /* attribute boolean printToFile; */
00187 NS_IMETHODIMP nsPrintSettings::GetPrintToFile(PRBool *aPrintToFile)
00188 {
00189   //NS_ENSURE_ARG_POINTER(aPrintToFile);
00190   *aPrintToFile = mPrintToFile;
00191   return NS_OK;
00192 }
00193 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(PRBool aPrintToFile)
00194 {
00195   mPrintToFile = aPrintToFile;
00196   return NS_OK;
00197 }
00198 
00199 /* attribute wstring toFileName; */
00200 NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName)
00201 {
00202   //NS_ENSURE_ARG_POINTER(aToFileName);
00203   *aToFileName = ToNewUnicode(mToFileName);
00204   return NS_OK;
00205 }
00206 NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
00207 {
00208   mToFileName = aToFileName;
00209   return NS_OK;
00210 }
00211 
00212 /* attribute long printPageDelay; */
00213 NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay)
00214 {
00215   *aPrintPageDelay = mPrintPageDelay;
00216   return NS_OK;
00217 }
00218 NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay)
00219 {
00220   mPrintPageDelay = aPrintPageDelay;
00221   return NS_OK;
00222 }
00223 
00224 /* attribute double marginTop; */
00225 NS_IMETHODIMP nsPrintSettings::GetMarginTop(double *aMarginTop)
00226 {
00227   NS_ENSURE_ARG_POINTER(aMarginTop);
00228   *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
00229   return NS_OK;
00230 }
00231 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
00232 {
00233   mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop));
00234   return NS_OK;
00235 }
00236 
00237 /* attribute double marginLeft; */
00238 NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double *aMarginLeft)
00239 {
00240   NS_ENSURE_ARG_POINTER(aMarginLeft);
00241   *aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
00242   return NS_OK;
00243 }
00244 NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft)
00245 {
00246   mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft));
00247   return NS_OK;
00248 }
00249 
00250 /* attribute double marginBottom; */
00251 NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double *aMarginBottom)
00252 {
00253   NS_ENSURE_ARG_POINTER(aMarginBottom);
00254   *aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
00255   return NS_OK;
00256 }
00257 NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom)
00258 {
00259   mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom));
00260   return NS_OK;
00261 }
00262 
00263 /* attribute double marginRight; */
00264 NS_IMETHODIMP nsPrintSettings::GetMarginRight(double *aMarginRight)
00265 {
00266   NS_ENSURE_ARG_POINTER(aMarginRight);
00267   *aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
00268   return NS_OK;
00269 }
00270 NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight)
00271 {
00272   mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight));
00273   return NS_OK;
00274 }
00275 
00276 /* attribute double scaling; */
00277 NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling)
00278 {
00279   NS_ENSURE_ARG_POINTER(aScaling);
00280   *aScaling = mScaling;
00281   return NS_OK;
00282 }
00283 
00284 NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling)
00285 {
00286   mScaling = aScaling;
00287   return NS_OK;
00288 }
00289 
00290 /* attribute boolean printBGColors; */
00291 NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(PRBool *aPrintBGColors)
00292 {
00293   NS_ENSURE_ARG_POINTER(aPrintBGColors);
00294   *aPrintBGColors = mPrintBGColors;
00295   return NS_OK;
00296 }
00297 NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors)
00298 {
00299   mPrintBGColors = aPrintBGColors;
00300   return NS_OK;
00301 }
00302 
00303 /* attribute boolean printBGImages; */
00304 NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(PRBool *aPrintBGImages)
00305 {
00306   NS_ENSURE_ARG_POINTER(aPrintBGImages);
00307   *aPrintBGImages = mPrintBGImages;
00308   return NS_OK;
00309 }
00310 NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages)
00311 {
00312   mPrintBGImages = aPrintBGImages;
00313   return NS_OK;
00314 }
00315 
00316 /* attribute long printRange; */
00317 NS_IMETHODIMP nsPrintSettings::GetPrintRange(PRInt16 *aPrintRange)
00318 {
00319   NS_ENSURE_ARG_POINTER(aPrintRange);
00320   *aPrintRange = mPrintRange;
00321   return NS_OK;
00322 }
00323 NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange)
00324 {
00325   mPrintRange = aPrintRange;
00326   return NS_OK;
00327 }
00328 
00329 /* attribute wstring docTitle; */
00330 NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle)
00331 {
00332   NS_ENSURE_ARG_POINTER(aTitle);
00333   *aTitle = ToNewUnicode(mTitle);
00334   return NS_OK;
00335 }
00336 NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle)
00337 {
00338   NS_ENSURE_ARG_POINTER(aTitle);
00339   mTitle = aTitle;
00340   return NS_OK;
00341 }
00342 
00343 /* attribute wstring docURL; */
00344 NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL)
00345 {
00346   NS_ENSURE_ARG_POINTER(aDocURL);
00347   *aDocURL = ToNewUnicode(mURL);
00348   return NS_OK;
00349 }
00350 NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL)
00351 {
00352   NS_ENSURE_ARG_POINTER(aDocURL);
00353   mURL = aDocURL;
00354   return NS_OK;
00355 }
00356 
00361 NS_IMETHODIMP 
00362 nsPrintSettings::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff)
00363 {
00364   NS_ENSURE_ARG_POINTER(aTurnOnOff);
00365   *aTurnOnOff = mPrintOptions & aType;
00366   return NS_OK;
00367 }
00372 NS_IMETHODIMP 
00373 nsPrintSettings::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff)
00374 {
00375   if (aTurnOnOff) {
00376     mPrintOptions |=  aType;
00377   } else {
00378     mPrintOptions &= ~aType;
00379   }
00380   return NS_OK;
00381 }
00382 
00387 NS_IMETHODIMP 
00388 nsPrintSettings::GetPrintOptionsBits(PRInt32 *aBits)
00389 {
00390   NS_ENSURE_ARG_POINTER(aBits);
00391   *aBits = mPrintOptions;
00392   return NS_OK;
00393 }
00394 
00395 /* attribute wstring docTitle; */
00396 nsresult 
00397 nsPrintSettings::GetMarginStrs(PRUnichar * *aTitle, 
00398                               nsHeaderFooterEnum aType, 
00399                               PRInt16 aJust)
00400 {
00401   NS_ENSURE_ARG_POINTER(aTitle);
00402   *aTitle = nsnull;
00403   if (aType == eHeader) {
00404     switch (aJust) {
00405       case kJustLeft:   *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
00406       case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
00407       case kJustRight:  *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
00408     } //switch
00409   } else {
00410     switch (aJust) {
00411       case kJustLeft:   *aTitle = ToNewUnicode(mFooterStrs[0]);break;
00412       case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
00413       case kJustRight:  *aTitle = ToNewUnicode(mFooterStrs[2]);break;
00414     } //switch
00415   }
00416   return NS_OK;
00417 }
00418 
00419 nsresult
00420 nsPrintSettings::SetMarginStrs(const PRUnichar * aTitle, 
00421                               nsHeaderFooterEnum aType, 
00422                               PRInt16 aJust)
00423 {
00424   NS_ENSURE_ARG_POINTER(aTitle);
00425   if (aType == eHeader) {
00426     switch (aJust) {
00427       case kJustLeft:   mHeaderStrs[0] = aTitle;break;
00428       case kJustCenter: mHeaderStrs[1] = aTitle;break;
00429       case kJustRight:  mHeaderStrs[2] = aTitle;break;
00430     } //switch
00431   } else {
00432     switch (aJust) {
00433       case kJustLeft:   mFooterStrs[0] = aTitle;break;
00434       case kJustCenter: mFooterStrs[1] = aTitle;break;
00435       case kJustRight:  mFooterStrs[2] = aTitle;break;
00436     } //switch
00437   }
00438   return NS_OK;
00439 }
00440 
00441 /* attribute wstring Header String Left */
00442 NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(PRUnichar * *aTitle)
00443 {
00444   return GetMarginStrs(aTitle, eHeader, kJustLeft);
00445 }
00446 NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const PRUnichar * aTitle)
00447 {
00448   return SetMarginStrs(aTitle, eHeader, kJustLeft);
00449 }
00450 
00451 /* attribute wstring Header String Center */
00452 NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(PRUnichar * *aTitle)
00453 {
00454   return GetMarginStrs(aTitle, eHeader, kJustCenter);
00455 }
00456 NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const PRUnichar * aTitle)
00457 {
00458   return SetMarginStrs(aTitle, eHeader, kJustCenter);
00459 }
00460 
00461 /* attribute wstring Header String Right */
00462 NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(PRUnichar * *aTitle)
00463 {
00464   return GetMarginStrs(aTitle, eHeader, kJustRight);
00465 }
00466 NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const PRUnichar * aTitle)
00467 {
00468   return SetMarginStrs(aTitle, eHeader, kJustRight);
00469 }
00470 
00471 
00472 /* attribute wstring Footer String Left */
00473 NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(PRUnichar * *aTitle)
00474 {
00475   return GetMarginStrs(aTitle, eFooter, kJustLeft);
00476 }
00477 NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const PRUnichar * aTitle)
00478 {
00479   return SetMarginStrs(aTitle, eFooter, kJustLeft);
00480 }
00481 
00482 /* attribute wstring Footer String Center */
00483 NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(PRUnichar * *aTitle)
00484 {
00485   return GetMarginStrs(aTitle, eFooter, kJustCenter);
00486 }
00487 NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const PRUnichar * aTitle)
00488 {
00489   return SetMarginStrs(aTitle, eFooter, kJustCenter);
00490 }
00491 
00492 /* attribute wstring Footer String Right */
00493 NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(PRUnichar * *aTitle)
00494 {
00495   return GetMarginStrs(aTitle, eFooter, kJustRight);
00496 }
00497 NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const PRUnichar * aTitle)
00498 {
00499   return SetMarginStrs(aTitle, eFooter, kJustRight);
00500 }
00501 
00502 /* attribute long printFrame; */
00503 NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(PRInt16 *aPrintFrameType)
00504 {
00505   NS_ENSURE_ARG_POINTER(aPrintFrameType);
00506   *aPrintFrameType = (PRInt32)mPrintFrameType;
00507   return NS_OK;
00508 }
00509 NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType)
00510 {
00511   mPrintFrameType = aPrintFrameType;
00512   return NS_OK;
00513 }
00514 
00515 /* attribute long isCancelled; */
00516 NS_IMETHODIMP nsPrintSettings::GetPrintSilent(PRBool *aPrintSilent)
00517 {
00518   NS_ENSURE_ARG_POINTER(aPrintSilent);
00519   *aPrintSilent = mPrintSilent;
00520   return NS_OK;
00521 }
00522 NS_IMETHODIMP nsPrintSettings::SetPrintSilent(PRBool aPrintSilent)
00523 {
00524   mPrintSilent = aPrintSilent;
00525   return NS_OK;
00526 }
00527