Back to index

lightning-sunbird  0.9+nobinonly
nsDeviceContextSpecQt.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Lars Knoll <knoll@kde.org>
00024  *   Zack Rusin <zack@kde.org>
00025  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /* Store per-printer features in temp. prefs vars that the
00042  * print dialog can pick them up... */
00043 #define SET_PRINTER_FEATURES_VIA_PREFS 1
00044 #define PRINTERFEATURES_PREF "print.tmp.printerfeatures"
00045 
00046 #define FORCE_PR_LOG /* Allow logging in the release build */
00047 #define PR_LOGGING 1
00048 #include "prlog.h"
00049 
00050 #include "nsDeviceContextSpecQt.h"
00051 
00052 #include "nsIPref.h"
00053 #include "prenv.h" /* for PR_GetEnv */
00054 
00055 #include "nsPrintfCString.h"
00056 #include "nsReadableUtils.h"
00057 #include "nsIServiceManager.h"
00058 #include "nsCRT.h"
00059 
00060 #ifdef USE_XPRINT
00061 #include "xprintutil.h"
00062 #endif /* USE_XPRINT */
00063 
00064 #ifdef USE_POSTSCRIPT
00065 /* Fetch |postscript_module_paper_sizes| */
00066 #undef USE_POSTSCRIPT
00067 #warning "fixme: postscript disabled"
00068 //#include "nsPaperPS.h"
00069 #endif /* USE_POSTSCRIPT */
00070 
00071 /* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
00072 #define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
00073 
00074 #ifdef PR_LOGGING
00075 static PRLogModuleInfo *DeviceContextSpecQtLM = PR_NewLogModule("DeviceContextSpecQt");
00076 #endif /* PR_LOGGING */
00077 /* Macro to make lines shorter */
00078 #define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecQtLM, PR_LOG_DEBUG, x)
00079 
00080 //----------------------------------------------------------------------------------
00081 // The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecQt
00082 // The PrinterEnumerator creates the printer info
00083 // but the nsDeviceContextSpecQt cleans it up
00084 // If it gets created (via the Page Setup Dialog) but the user never prints anything
00085 // then it will never be delete, so this class takes care of that.
00086 class GlobalPrinters {
00087 public:
00088   static GlobalPrinters* GetInstance()   { return &mGlobalPrinters; }
00089   ~GlobalPrinters()                      { FreeGlobalPrinters(); }
00090 
00091   void      FreeGlobalPrinters();
00092   nsresult  InitializeGlobalPrinters();
00093 
00094   PRBool    PrintersAreAllocated()       { return mGlobalPrinterList != nsnull; }
00095   PRInt32   GetNumPrinters()             { return mGlobalNumPrinters; }
00096   nsString* GetStringAt(PRInt32 aInx)    { return mGlobalPrinterList->StringAt(aInx); }
00097   void      GetDefaultPrinterName(PRUnichar **aDefaultPrinterName);
00098 
00099 protected:
00100   GlobalPrinters() {}
00101 
00102   static GlobalPrinters mGlobalPrinters;
00103   static nsStringArray* mGlobalPrinterList;
00104   static int            mGlobalNumPrinters;
00105 };
00106 
00107 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00108 /* "Prototype" for the new nsPrinterFeatures service */
00109 class nsPrinterFeatures {
00110 public:
00111   nsPrinterFeatures( const char *printername );
00112   ~nsPrinterFeatures() {};
00113 
00114   /* Does this device allow to set/change the paper size ? */
00115   void SetCanChangePaperSize( PRBool aCanSetPaperSize );
00116   /* Set number of paper size records and the records itself */
00117   void SetNumPaperSizeRecords( PRInt32 aCount );
00118   void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch );
00119 
00120   /* Does this device allow to set/change the content orientation ? */
00121   void SetCanChangeOrientation( PRBool aCanSetOrientation );
00122   /* Set number of orientation records and the records itself */
00123   void SetNumOrientationRecords( PRInt32 aCount );
00124   void SetOrientationRecord( PRInt32 aIndex, const char *aName );
00125 
00126   /* Does this device allow to set/change the spooler command ? */
00127   void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand );
00128 
00129   /* Does this device allow to set/change number of copies for an document ? */
00130   void SetCanChangeNumCopies( PRBool aCanSetNumCopies );
00131 
00132   /* Does this device allow multiple devicecontext instances to be used in
00133    * parallel (e.g. print while the device is already in use by print-preview
00134    * or printing while another print job is in progress) ? */
00135   void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances );
00136 
00137 private:
00138   /* private helper methods */
00139   void SetBoolValue( const char *tagname, PRBool value );
00140   void SetIntValue(  const char *tagname, PRInt32 value );
00141   void SetCharValue(  const char *tagname, const char *value );
00142 
00143   nsXPIDLCString    mPrinterName;
00144   nsCOMPtr<nsIPref> mPrefs;
00145 };
00146 
00147 void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value )
00148 {
00149   mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
00150 }
00151 
00152 void nsPrinterFeatures::SetIntValue(  const char *tagname, PRInt32 value )
00153 {
00154   mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
00155 }
00156 
00157 void nsPrinterFeatures::SetCharValue(  const char *tagname, const char *value )
00158 {
00159   mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
00160 }
00161 
00162 nsPrinterFeatures::nsPrinterFeatures( const char *printername )
00163 {
00164   DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername));
00165   mPrinterName.Assign(printername);
00166   mPrefs = do_GetService(NS_PREF_CONTRACTID);
00167 
00168   SetBoolValue("has_special_printerfeatures", PR_TRUE);
00169 }
00170 
00171 void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize )
00172 {
00173   SetBoolValue("can_change_paper_size", aCanSetPaperSize);
00174 }
00175 
00176 /* Set number of paper size records and the records itself */
00177 void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount )
00178 {
00179   SetIntValue("paper.count", aCount);
00180 }
00181 
00182 void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch)
00183 {
00184   SetCharValue(nsPrintfCString(256, "paper.%d.name",      aIndex).get(), aPaperName);
00185   SetIntValue( nsPrintfCString(256, "paper.%d.width_mm",  aIndex).get(), aWidthMM);
00186   SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM);
00187   SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch",   aIndex).get(), aIsInch);
00188 }
00189 
00190 void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation )
00191 {
00192   SetBoolValue("can_change_orientation", aCanSetOrientation);
00193 }
00194 
00195 void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount )
00196 {
00197   SetIntValue("orientation.count", aCount);
00198 }
00199 
00200 void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName )
00201 {
00202   SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName);
00203 }
00204 
00205 void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand )
00206 {
00207   SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand);
00208 }
00209 
00210 void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies )
00211 {
00212   SetBoolValue("can_change_num_copies", aCanSetNumCopies);
00213 }
00214 
00215 void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances )
00216 {
00217   SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances);
00218 }
00219 
00220 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00221 
00222 //---------------
00223 // static members
00224 GlobalPrinters GlobalPrinters::mGlobalPrinters;
00225 nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull;
00226 int            GlobalPrinters::mGlobalNumPrinters = 0;
00227 //---------------
00228 
00229 nsDeviceContextSpecQt::nsDeviceContextSpecQt()
00230 {
00231   DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::nsDeviceContextSpecQt()\n"));
00232 }
00233 
00234 nsDeviceContextSpecQt::~nsDeviceContextSpecQt()
00235 {
00236   DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::~nsDeviceContextSpecQt()\n"));
00237 }
00238 
00239 /* Use both PostScript and Xprint module */
00240 #if defined(USE_XPRINT) && defined(USE_POSTSCRIPT)
00241 NS_IMPL_ISUPPORTS3(nsDeviceContextSpecQt,
00242                    nsIDeviceContextSpec,
00243                    nsIDeviceContextSpecPS,
00244                    nsIDeviceContextSpecXp)
00245 /* Use only PostScript module */
00246 #elif !defined(USE_XPRINT) && defined(USE_POSTSCRIPT)
00247 NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQt,
00248                    nsIDeviceContextSpec,
00249                    nsIDeviceContextSpecPS)
00250 /* Use only Xprint module module */
00251 #elif defined(USE_XPRINT) && !defined(USE_POSTSCRIPT)
00252 NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQt,
00253                    nsIDeviceContextSpec,
00254                    nsIDeviceContextSpecXp)
00255 /* Both Xprint and PostScript module are missing */
00256 #elif !defined(USE_XPRINT) && !defined(USE_POSTSCRIPT)
00257 NS_IMPL_ISUPPORTS1(nsDeviceContextSpecQt,
00258                    nsIDeviceContextSpec)
00259 #else
00260 #error "This should not happen"
00261 #endif
00262 
00282 NS_IMETHODIMP nsDeviceContextSpecQt::Init(nsIPrintSettings *aPS)
00283 {
00284   DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::Init(aPS=%p\n", aPS));
00285   nsresult rv = NS_ERROR_FAILURE;
00286 
00287   mPrintSettings = aPS;
00288 
00289   // if there is a current selection then enable the "Selection" radio button
00290   if (mPrintSettings) {
00291     PRBool isOn;
00292     mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
00293     nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
00294     if (NS_SUCCEEDED(rv)) {
00295       (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
00296     }
00297   }
00298 
00299   rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
00300   if (NS_FAILED(rv)) {
00301     return rv;
00302   }
00303 
00304   GlobalPrinters::GetInstance()->FreeGlobalPrinters();
00305 
00306   if (aPS) {
00307     PRBool     reversed       = PR_FALSE;
00308     PRBool     color          = PR_FALSE;
00309     PRBool     tofile         = PR_FALSE;
00310     PRInt16    printRange     = nsIPrintSettings::kRangeAllPages;
00311     PRInt32    orientation    = NS_PORTRAIT;
00312     PRInt32    fromPage       = 1;
00313     PRInt32    toPage         = 1;
00314     PRUnichar *command        = nsnull;
00315     PRInt32    copies         = 1;
00316     PRUnichar *printer        = nsnull;
00317     PRUnichar *papername      = nsnull;
00318     PRUnichar *printfile      = nsnull;
00319     double     dleft          = 0.5;
00320     double     dright         = 0.5;
00321     double     dtop           = 0.5;
00322     double     dbottom        = 0.5;
00323 
00324     aPS->GetPrinterName(&printer);
00325     aPS->GetPrintReversed(&reversed);
00326     aPS->GetPrintInColor(&color);
00327     aPS->GetPaperName(&papername);
00328     aPS->GetOrientation(&orientation);
00329     aPS->GetPrintCommand(&command);
00330     aPS->GetPrintRange(&printRange);
00331     aPS->GetToFileName(&printfile);
00332     aPS->GetPrintToFile(&tofile);
00333     aPS->GetStartPageRange(&fromPage);
00334     aPS->GetEndPageRange(&toPage);
00335     aPS->GetNumCopies(&copies);
00336     aPS->GetMarginTop(&dtop);
00337     aPS->GetMarginLeft(&dleft);
00338     aPS->GetMarginBottom(&dbottom);
00339     aPS->GetMarginRight(&dright);
00340 
00341     if (printfile)
00342       strcpy(mPath,    NS_ConvertUCS2toUTF8(printfile).get());
00343     if (command)
00344       strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get());
00345     if (printer)
00346       strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get());
00347     if (papername)
00348       strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get());
00349 
00350     DO_PR_DEBUG_LOG(("margins:   %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
00351     DO_PR_DEBUG_LOG(("printRange %d\n",   printRange));
00352     DO_PR_DEBUG_LOG(("fromPage   %d\n",   fromPage));
00353     DO_PR_DEBUG_LOG(("toPage     %d\n",   toPage));
00354     DO_PR_DEBUG_LOG(("tofile     %d\n",   tofile));
00355     DO_PR_DEBUG_LOG(("printfile  '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>"));
00356     DO_PR_DEBUG_LOG(("command    '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>"));
00357     DO_PR_DEBUG_LOG(("printer    '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>"));
00358     DO_PR_DEBUG_LOG(("papername  '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"<NULL>"));
00359 
00360     mTop         = dtop;
00361     mBottom      = dbottom;
00362     mLeft        = dleft;
00363     mRight       = dright;
00364     mFpf         = !reversed;
00365     mGrayscale   = !color;
00366     mOrientation = orientation;
00367     mToPrinter   = !tofile;
00368     mCopies      = copies;
00369   }
00370 
00371   return rv;
00372 }
00373 
00374 NS_IMETHODIMP nsDeviceContextSpecQt::GetToPrinter(PRBool &aToPrinter)
00375 {
00376   aToPrinter = mToPrinter;
00377   return NS_OK;
00378 }
00379 
00380 NS_IMETHODIMP nsDeviceContextSpecQt::GetPrinterName ( const char **aPrinter )
00381 {
00382    *aPrinter = mPrinter;
00383    return NS_OK;
00384 }
00385 
00386 NS_IMETHODIMP nsDeviceContextSpecQt::GetCopies ( int &aCopies )
00387 {
00388    aCopies = mCopies;
00389    return NS_OK;
00390 }
00391 
00392 NS_IMETHODIMP nsDeviceContextSpecQt::GetFirstPageFirst(PRBool &aFpf)
00393 {
00394   aFpf = mFpf;
00395   return NS_OK;
00396 }
00397 
00398 NS_IMETHODIMP nsDeviceContextSpecQt::GetGrayscale(PRBool &aGrayscale)
00399 {
00400   aGrayscale = mGrayscale;
00401   return NS_OK;
00402 }
00403 
00404 NS_IMETHODIMP nsDeviceContextSpecQt::GetLandscape(PRBool &aLandscape)
00405 {
00406   aLandscape = (mOrientation == NS_LANDSCAPE);
00407   return NS_OK;
00408 }
00409 
00410 NS_IMETHODIMP nsDeviceContextSpecQt::GetTopMargin(float &aValue)
00411 {
00412   aValue = mTop;
00413   return NS_OK;
00414 }
00415 
00416 NS_IMETHODIMP nsDeviceContextSpecQt::GetBottomMargin(float &aValue)
00417 {
00418   aValue = mBottom;
00419   return NS_OK;
00420 }
00421 
00422 NS_IMETHODIMP nsDeviceContextSpecQt::GetRightMargin(float &aValue)
00423 {
00424   aValue = mRight;
00425   return NS_OK;
00426 }
00427 
00428 NS_IMETHODIMP nsDeviceContextSpecQt::GetLeftMargin(float &aValue)
00429 {
00430   aValue = mLeft;
00431   return NS_OK;
00432 }
00433 
00434 NS_IMETHODIMP nsDeviceContextSpecQt::GetCommand(const char **aCommand)
00435 {
00436   *aCommand = mCommand;
00437   return NS_OK;
00438 }
00439 
00440 NS_IMETHODIMP nsDeviceContextSpecQt::GetPath(const char **aPath)
00441 {
00442   *aPath = mPath;
00443   return NS_OK;
00444 }
00445 
00446 NS_IMETHODIMP nsDeviceContextSpecQt::GetUserCancelled(PRBool &aCancel)
00447 {
00448   aCancel = mCancel;
00449   return NS_OK;
00450 }
00451 
00452 NS_IMETHODIMP nsDeviceContextSpecQt::GetPaperName( const char **aPaperName )
00453 {
00454   *aPaperName = mPaperName;
00455   return NS_OK;
00456 }
00457 
00458 NS_IMETHODIMP nsDeviceContextSpecQt::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
00459 {
00460   return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight);
00461 }
00462 
00463 NS_IMETHODIMP nsDeviceContextSpecQt::GetPrintMethod(PrintMethod &aMethod)
00464 {
00465   return GetPrintMethod(mPrinter, aMethod);
00466 }
00467 
00468 /* static !! */
00469 nsresult nsDeviceContextSpecQt::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod)
00470 {
00471 #if defined(USE_POSTSCRIPT) && defined(USE_XPRINT)
00472   /* printer names for the PostScript module alwas start with
00473    * the NS_POSTSCRIPT_DRIVER_NAME string */
00474   if (strncmp(aPrinter, NS_POSTSCRIPT_DRIVER_NAME,
00475               NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0)
00476     aMethod = pmXprint;
00477   else
00478     aMethod = pmPostScript;
00479   return NS_OK;
00480 #elif defined(USE_XPRINT)
00481   aMethod = pmXprint;
00482   return NS_OK;
00483 #elif defined(USE_POSTSCRIPT)
00484   aMethod = pmPostScript;
00485   return NS_OK;
00486 #else
00487   return NS_ERROR_UNEXPECTED;
00488 #endif
00489 }
00490 
00491 NS_IMETHODIMP nsDeviceContextSpecQt::ClosePrintManager()
00492 {
00493   return NS_OK;
00494 }
00495 
00496 /* Get prefs for printer
00497  * Search order:
00498  * - Get prefs per printer name and module name
00499  * - Get prefs per printer name
00500  * - Get prefs per module name
00501  * - Get prefs
00502  */
00503 static
00504 nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char *printername, const char *prefname, char **return_buf)
00505 {
00506   DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname));
00507 
00508   NS_ENSURE_ARG_POINTER(return_buf);
00509 
00510   nsXPIDLCString name;
00511   nsresult rv = NS_ERROR_FAILURE;
00512 
00513   if (printername && modulename) {
00514     /* Get prefs per printer name and module name */
00515     name = nsPrintfCString(512, "print.%s.printer_%s.%s", modulename, printername, prefname);
00516     DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
00517     rv = pref->CopyCharPref(name, return_buf);
00518   }
00519 
00520   if (NS_FAILED(rv)) {
00521     if (printername) {
00522       /* Get prefs per printer name */
00523       name = nsPrintfCString(512, "print.printer_%s.%s", printername, prefname);
00524       DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
00525       rv = pref->CopyCharPref(name, return_buf);
00526     }
00527 
00528     if (NS_FAILED(rv)) {
00529       if (modulename) {
00530         /* Get prefs per module name */
00531         name = nsPrintfCString(512, "print.%s.%s", modulename, prefname);
00532         DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
00533         rv = pref->CopyCharPref(name, return_buf);
00534       }
00535 
00536       if (NS_FAILED(rv)) {
00537         /* Get prefs */
00538         name = nsPrintfCString(512, "print.%s", prefname);
00539         DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
00540         rv = pref->CopyCharPref(name, return_buf);
00541       }
00542     }
00543   }
00544 
00545 #ifdef PR_LOG
00546   if (NS_SUCCEEDED(rv)) {
00547     DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", *return_buf));
00548   }
00549   else
00550   {
00551     DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n"));
00552   }
00553 #endif /* PR_LOG */
00554 
00555   return rv;
00556 }
00557 
00558 //  Printer Enumerator
00559 nsPrinterEnumeratorQt::nsPrinterEnumeratorQt()
00560 {
00561 }
00562 
00563 NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorQt, nsIPrinterEnumerator)
00564 
00565 NS_IMETHODIMP nsPrinterEnumeratorQt::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
00566 {
00567   NS_ENSURE_ARG(aCount);
00568   NS_ENSURE_ARG_POINTER(aResult);
00569 
00570   if (aCount)
00571     *aCount = 0;
00572   else
00573     return NS_ERROR_NULL_POINTER;
00574 
00575   if (aResult)
00576     *aResult = nsnull;
00577   else
00578     return NS_ERROR_NULL_POINTER;
00579 
00580   nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
00581   if (NS_FAILED(rv)) {
00582     return rv;
00583   }
00584 
00585   PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
00586 
00587   PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*));
00588   if (!array && numPrinters > 0) {
00589     GlobalPrinters::GetInstance()->FreeGlobalPrinters();
00590     return NS_ERROR_OUT_OF_MEMORY;
00591   }
00592 
00593   int count = 0;
00594   while( count < numPrinters )
00595   {
00596     PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count));
00597 
00598     if (!str) {
00599       for (int i = count - 1; i >= 0; i--)
00600         nsMemory::Free(array[i]);
00601 
00602       nsMemory::Free(array);
00603 
00604       GlobalPrinters::GetInstance()->FreeGlobalPrinters();
00605       return NS_ERROR_OUT_OF_MEMORY;
00606     }
00607     array[count++] = str;
00608 
00609   }
00610   *aCount = count;
00611   *aResult = array;
00612   GlobalPrinters::GetInstance()->FreeGlobalPrinters();
00613 
00614   return NS_OK;
00615 }
00616 
00617 /* readonly attribute wstring defaultPrinterName; */
00618 NS_IMETHODIMP nsPrinterEnumeratorQt::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
00619 {
00620   DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::GetDefaultPrinterName()\n"));
00621   NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
00622 
00623   GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName);
00624 
00625   DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUCS2toUTF8(*aDefaultPrinterName).get()));
00626   return NS_OK;
00627 }
00628 
00629 /* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
00630 NS_IMETHODIMP nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
00631 {
00632   DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter()"));
00633   nsresult rv;
00634 
00635   NS_ENSURE_ARG_POINTER(aPrinterName);
00636   NS_ENSURE_ARG_POINTER(aPrintSettings);
00637 
00638   NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE);
00639   NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE);
00640 
00641   nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
00642   if (NS_FAILED(rv))
00643     return rv;
00644 
00645   nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */
00646                  printerName;     /* "Stripped" name of printer */
00647   fullPrinterName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
00648   printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
00649   DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get()));
00650 
00651   PrintMethod type = pmInvalid;
00652   rv = nsDeviceContextSpecQt::GetPrintMethod(printerName, type);
00653   if (NS_FAILED(rv))
00654     return rv;
00655 
00656 #ifdef USE_POSTSCRIPT
00657   /* "Demangle" postscript printer name */
00658   if (type == pmPostScript) {
00659     /* Strip the leading NS_POSTSCRIPT_DRIVER_NAME from |printerName|,
00660      * e.g. turn "PostScript/foobar" to "foobar" */
00661     printerName.Cut(0, NS_POSTSCRIPT_DRIVER_NAME_LEN);
00662   }
00663 #endif /* USE_POSTSCRIPT */
00664 
00665 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00666   /* Defaults to FALSE */
00667   pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE);
00668 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00669 
00670 
00671   /* Set filename */
00672   nsXPIDLCString filename;
00673   if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) {
00674     const char *path;
00675 
00676     if (!(path = PR_GetEnv("PWD")))
00677       path = PR_GetEnv("HOME");
00678 
00679     if (path)
00680       filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
00681     else
00682       filename.Assign("mozilla.ps");
00683   }
00684   DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
00685   aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get());
00686 
00687   aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE);
00688 #ifdef USE_XPRINT
00689   if (type == pmXprint) {
00690     DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for Xprint printer\n"));
00691 
00692     Display   *pdpy;
00693     XPContext  pcontext;
00694     if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1)
00695       return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
00696 
00697     XpuSupportedFlags supported_doc_attrs = XpuGetSupportedDocAttributes(pdpy, pcontext);
00698 
00699 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00700     nsPrinterFeatures printerFeatures(fullPrinterName);
00701 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00702 
00703     /* Setup orientation stuff */
00704     XpuOrientationList  olist;
00705     int                 ocount;
00706     XpuOrientationRec  *default_orientation;
00707 
00708 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00709     PRBool canSetOrientation = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION);
00710     printerFeatures.SetCanChangeOrientation(canSetOrientation);
00711 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00712 
00713     /* Get list of supported orientations */
00714     olist = XpuGetOrientationList(pdpy, pcontext, &ocount);
00715     if (olist) {
00716       default_orientation = &olist[0]; /* First entry is the default one */
00717 
00718       if (!PL_strcasecmp(default_orientation->orientation, "portrait")) {
00719         DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
00720         aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
00721       }
00722       else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) {
00723         DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
00724         aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
00725       }
00726       else {
00727         DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation));
00728       }
00729 
00730 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00731       int i;
00732       for( i = 0 ; i < ocount ; i++ )
00733       {
00734         XpuOrientationRec *curr = &olist[i];
00735         printerFeatures.SetOrientationRecord(i, curr->orientation);
00736       }
00737       printerFeatures.SetNumOrientationRecords(ocount);
00738 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00739 
00740       XpuFreeOrientationList(olist);
00741     }
00742 
00743     /* Setup Number of Copies */
00744 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00745     PRBool canSetNumCopies = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_COPY_COUNT);
00746     printerFeatures.SetCanChangeNumCopies(canSetNumCopies);
00747 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00748     long numCopies;
00749     if( XpuGetOneLongAttribute(pdpy, pcontext, XPDocAttr, "copy-count", &numCopies) != 1 )
00750     {
00751       /* Fallback on failure */
00752       numCopies = 1;
00753     }
00754     aPrintSettings->SetNumCopies(numCopies);
00755 
00756     /* Setup paper size stuff */
00757     XpuMediumSourceSizeList mlist;
00758     int                     mcount;
00759     XpuMediumSourceSizeRec *default_medium;
00760 
00761 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00762     PRBool canSetPaperSize = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM);
00763     printerFeatures.SetCanChangePaperSize(canSetPaperSize);
00764 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00765 
00766     mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount);
00767     if (mlist) {
00768       nsXPIDLCString papername;
00769 
00770       default_medium = &mlist[0]; /* First entry is the default one */
00771       double total_width  = default_medium->ma1 + default_medium->ma2,
00772              total_height = default_medium->ma3 + default_medium->ma4;
00773 
00774       /* Either "paper" or "tray/paper" */
00775       if (default_medium->tray_name) {
00776         papername = nsPrintfCString(256, "%s/%s", default_medium->tray_name, default_medium->medium_name);
00777       }
00778       else {
00779         papername.Assign(default_medium->medium_name);
00780       }
00781 
00782       DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g/%g mm)\n", papername.get(), total_width, total_height));
00783       aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
00784       aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
00785       aPrintSettings->SetPaperWidth(total_width);
00786       aPrintSettings->SetPaperHeight(total_height);
00787       aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(papername).get());
00788 
00789 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00790       int i;
00791       for( i = 0 ; i < mcount ; i++ )
00792       {
00793         XpuMediumSourceSizeRec *curr = &mlist[i];
00794         double total_width  = curr->ma1 + curr->ma2,
00795                total_height = curr->ma3 + curr->ma4;
00796         if (curr->tray_name) {
00797           papername = nsPrintfCString(256, "%s/%s", curr->tray_name, curr->medium_name);
00798         }
00799         else {
00800           papername.Assign(curr->medium_name);
00801         }
00802 
00803         printerFeatures.SetPaperRecord(i, papername, PRInt32(total_width), PRInt32(total_height), PR_FALSE);
00804       }
00805       printerFeatures.SetNumPaperSizeRecords(mcount);
00806 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00807 
00808       XpuFreeMediumSourceSizeList(mlist);
00809     }
00810 
00811 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00812     /* Xprint does not allow the client to set a spooler command.
00813      * Job spooling is the job of the server side (=Xprt) */
00814     printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE);
00815 
00816     /* Mozilla's Xprint support allows multiple nsIDeviceContext instances
00817      * be used in parallel */
00818     printerFeatures.SetMultipleConcurrentDeviceContextsSupported(PR_TRUE);
00819 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00820 
00821     XpuClosePrinterDisplay(pdpy, pcontext);
00822 
00823     return NS_OK;
00824   }
00825   else
00826 #endif /* USE_XPRINT */
00827 
00828 #ifdef USE_POSTSCRIPT
00829   if (type == pmPostScript) {
00830     DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n"));
00831 
00832 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00833     nsPrinterFeatures printerFeatures(fullPrinterName);
00834 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00835 
00836 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00837     printerFeatures.SetCanChangeOrientation(PR_TRUE);
00838 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00839 
00840     nsXPIDLCString orientation;
00841     if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) {
00842       if (!PL_strcasecmp(orientation, "portrait")) {
00843         DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
00844         aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
00845       }
00846       else if (!PL_strcasecmp(orientation, "landscape")) {
00847         DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
00848         aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
00849       }
00850       else {
00851         DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
00852       }
00853     }
00854 
00855 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00856     int i;
00857     for( i = 0 ; postscript_module_orientations[i].orientation != nsnull ; i++ )
00858     {
00859       const PSOrientationRec *curr = &postscript_module_orientations[i];
00860       printerFeatures.SetOrientationRecord(i, curr->orientation);
00861     }
00862     printerFeatures.SetNumOrientationRecords(i);
00863 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00864 
00865 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00866     printerFeatures.SetCanChangePaperSize(PR_TRUE);
00867 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00868     nsXPIDLCString papername;
00869     if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) {
00870       int                   i;
00871       const PSPaperSizeRec *default_paper = nsnull;
00872 
00873       for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
00874       {
00875         const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
00876 
00877         if (!PL_strcasecmp(papername, curr->name)) {
00878           default_paper = curr;
00879           break;
00880         }
00881       }
00882 
00883       if (default_paper) {
00884         DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g inch/%g inch)\n",
00885                         default_paper->name,
00886                         PSPaperSizeRec_FullPaperWidth(default_paper),
00887                         PSPaperSizeRec_FullPaperHeight(default_paper)));
00888         aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
00889         aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
00890         aPrintSettings->SetPaperWidth(PSPaperSizeRec_FullPaperWidth(default_paper));
00891         aPrintSettings->SetPaperHeight(PSPaperSizeRec_FullPaperHeight(default_paper));
00892         aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(default_paper->name).get());
00893       }
00894       else {
00895         DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get()));
00896       }
00897 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00898       for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
00899       {
00900         const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
00901 #define CONVERT_INCH_TO_MILLIMETERS(inch) ((inch) * 25.4)
00902         double total_width  = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperWidth(curr)),
00903                total_height = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperHeight(curr));
00904 
00905         printerFeatures.SetPaperRecord(i, curr->name, PRInt32(total_width), PRInt32(total_height), PR_TRUE);
00906       }
00907       printerFeatures.SetNumPaperSizeRecords(i);
00908 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00909     }
00910 
00911 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00912     printerFeatures.SetCanChangeSpoolerCommand(PR_TRUE);
00913 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00914 
00915     nsXPIDLCString command;
00916     if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) {
00917       DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get()));
00918       aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get());
00919     }
00920 
00921 #ifdef SET_PRINTER_FEATURES_VIA_PREFS
00922     printerFeatures.SetCanChangeNumCopies(PR_TRUE);
00923 #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
00924 
00925     return NS_OK;
00926   }
00927 #endif /* USE_POSTSCRIPT */
00928 
00929   return NS_ERROR_UNEXPECTED;
00930 }
00931 
00932 NS_IMETHODIMP nsPrinterEnumeratorQt::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
00933 {
00934   return NS_OK;
00935 }
00936 
00937 //----------------------------------------------------------------------
00938 nsresult GlobalPrinters::InitializeGlobalPrinters ()
00939 {
00940   if (PrintersAreAllocated()) {
00941     return NS_OK;
00942   }
00943 
00944   mGlobalNumPrinters = 0;
00945   mGlobalPrinterList = new nsStringArray();
00946   if (!mGlobalPrinterList)
00947     return NS_ERROR_OUT_OF_MEMORY;
00948 
00949 #ifdef USE_XPRINT
00950   XPPrinterList plist = XpuGetPrinterList(nsnull, &mGlobalNumPrinters);
00951 
00952   if (plist && (mGlobalNumPrinters > 0))
00953   {
00954     int i;
00955     for(  i = 0 ; i < mGlobalNumPrinters ; i++ )
00956     {
00957       mGlobalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name)));
00958     }
00959 
00960     XpuFreePrinterList(plist);
00961   }
00962 #endif /* USE_XPRINT */
00963 
00964 #ifdef USE_POSTSCRIPT
00965   /* Get the list of PostScript-module printers */
00966   char   *printerList           = nsnull;
00967   PRBool  added_default_printer = PR_FALSE; /* Did we already add the default printer ? */
00968 
00969   /* The env var MOZILLA_POSTSCRIPT_PRINTER_LIST can "override" the prefs */
00970   printerList = PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST");
00971 
00972   if (!printerList) {
00973     nsresult rv;
00974     nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
00975     if (NS_SUCCEEDED(rv)) {
00976       (void) pPrefs->CopyCharPref("print.printer_list", &printerList);
00977     }
00978   }
00979 
00980   if (printerList) {
00981     char       *tok_lasts;
00982     const char *name;
00983 
00984     /* PL_strtok_r() will modify the string - copy it! */
00985     printerList = strdup(printerList);
00986     if (!printerList)
00987       return NS_ERROR_OUT_OF_MEMORY;
00988 
00989     for( name = PL_strtok_r(printerList, " ", &tok_lasts) ;
00990          name != nsnull ;
00991          name = PL_strtok_r(nsnull, " ", &tok_lasts) )
00992     {
00993       /* Is this the "default" printer ? */
00994       if (!strcmp(name, "default"))
00995         added_default_printer = PR_TRUE;
00996 
00997       mGlobalPrinterList->AppendString(
00998         nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) +
00999         nsString(NS_ConvertASCIItoUCS2(name)));
01000       mGlobalNumPrinters++;
01001     }
01002 
01003     free(printerList);
01004   }
01005 
01006   /* Add an entry for the default printer (see nsPostScriptObj.cpp) if we
01007    * did not add it already... */
01008   if (!added_default_printer)
01009   {
01010     mGlobalPrinterList->AppendString(
01011       nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default")));
01012     mGlobalNumPrinters++;
01013   }
01014 #endif /* USE_POSTSCRIPT */
01015 
01016   if (mGlobalNumPrinters == 0)
01017     return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
01018 
01019   return NS_OK;
01020 }
01021 
01022 //----------------------------------------------------------------------
01023 void GlobalPrinters::FreeGlobalPrinters()
01024 {
01025   delete mGlobalPrinterList;
01026   mGlobalPrinterList = nsnull;
01027   mGlobalNumPrinters = 0;
01028 }
01029 
01030 void
01031 GlobalPrinters::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
01032 {
01033   *aDefaultPrinterName = nsnull;
01034 
01035   PRBool allocate = (GlobalPrinters::GetInstance()->PrintersAreAllocated() == PR_FALSE);
01036 
01037   if (allocate) {
01038     nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
01039     if (NS_FAILED(rv)) {
01040       return;
01041     }
01042   }
01043   NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters");
01044 
01045   if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0)
01046     return;
01047 
01048   *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0));
01049 
01050   if (allocate) {
01051     GlobalPrinters::GetInstance()->FreeGlobalPrinters();
01052   }
01053 }
01054