Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes
GlobalPrinters Class Reference
Collaboration diagram for GlobalPrinters:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ~GlobalPrinters ()
void FreeGlobalPrinters ()
nsresult InitializeGlobalPrinters ()
PRBool PrintersAreAllocated ()
PRInt32 GetNumPrinters ()
nsStringGetStringAt (PRInt32 aInx)
 ~GlobalPrinters ()
void FreeGlobalPrinters ()
nsresult InitializeGlobalPrinters ()
PRBool PrintersAreAllocated ()
PRInt32 GetNumPrinters ()
nsStringGetStringAt (PRInt32 aInx)
void GetDefaultPrinterName (PRUnichar **aDefaultPrinterName)
 ~GlobalPrinters ()
void FreeGlobalPrinters ()
nsresult InitializeGlobalPrinters ()
PRBool PrintersAreAllocated ()
PRInt32 GetNumPrinters ()
nsStringGetStringAt (PRInt32 aInx)
void GetDefaultPrinterName (PRUnichar *&aDefaultPrinterName)
 ~GlobalPrinters ()
void FreeGlobalPrinters ()
nsresult InitializeGlobalPrinters ()
PRBool PrintersAreAllocated ()
PRInt32 GetNumPrinters ()
nsStringGetStringAt (PRInt32 aInx)
void GetDefaultPrinterName (PRUnichar **aDefaultPrinterName)
 ~GlobalPrinters ()
void FreeGlobalPrinters ()
PRBool PrintersAreAllocated ()
LPTSTR GetItemFromList (PRInt32 aInx)
nsresult EnumeratePrinterList ()
void GetDefaultPrinterName (LPTSTR &aDefaultPrinterName)
PRInt32 GetNumPrinters ()
 ~GlobalPrinters ()
void FreeGlobalPrinters ()
nsresult InitializeGlobalPrinters ()
PRBool PrintersAreAllocated ()
PRInt32 GetNumPrinters ()
nsStringGetStringAt (PRInt32 aInx)
void GetDefaultPrinterName (PRUnichar **aDefaultPrinterName)

Static Public Member Functions

static GlobalPrintersGetInstance ()
static GlobalPrintersGetInstance ()
static GlobalPrintersGetInstance ()
static GlobalPrintersGetInstance ()
static GlobalPrintersGetInstance ()
static GlobalPrintersGetInstance ()

Protected Member Functions

 GlobalPrinters ()
 GlobalPrinters ()
 GlobalPrinters ()
 GlobalPrinters ()
 GlobalPrinters ()
nsresult EnumerateNativePrinters ()
void ReallocatePrinters ()
 GlobalPrinters ()

Static Protected Attributes

static GlobalPrinters mGlobalPrinters
static nsStringArray * mGlobalPrinterList = nsnull
static int mGlobalNumPrinters = 0
static ULONG mGlobalNumPrinters
static nsVoidArraymPrinters = nsnull

Detailed Description

Definition at line 53 of file nsDeviceContextSpecB.cpp.


Constructor & Destructor Documentation

Definition at line 56 of file nsDeviceContextSpecB.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 66 of file nsDeviceContextSpecB.cpp.

{}

Definition at line 89 of file nsDeviceContextSpecG.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 101 of file nsDeviceContextSpecG.cpp.

{}

Definition at line 66 of file nsDeviceContextSpecOS2.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 77 of file nsDeviceContextSpecOS2.cpp.

{}

Definition at line 89 of file nsDeviceContextSpecQt.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 100 of file nsDeviceContextSpecQt.cpp.

{}

Definition at line 87 of file nsDeviceContextSpecWin.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 98 of file nsDeviceContextSpecWin.cpp.

{}

Definition at line 89 of file nsDeviceContextSpecXlib.cpp.

Here is the call graph for this function:

GlobalPrinters::GlobalPrinters ( ) [inline, protected]

Definition at line 101 of file nsDeviceContextSpecXlib.cpp.

{}

Member Function Documentation

Definition at line 1076 of file nsDeviceContextSpecWin.cpp.

{
  nsresult rv = NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
#ifndef WINCE
  PR_PL(("-----------------------\n"));
  PR_PL(("EnumerateNativePrinters\n"));

  TCHAR szDefaultPrinterName[1024];    
  DWORD status = GetProfileString("devices", 0, ",", szDefaultPrinterName, sizeof(szDefaultPrinterName)/sizeof(TCHAR));
  if (status > 0) {
    DWORD count = 0;
    LPTSTR sPtr   = (LPTSTR)szDefaultPrinterName;
    LPTSTR ePtr   = (LPTSTR)(szDefaultPrinterName+(status*sizeof(TCHAR)));
    LPTSTR prvPtr = sPtr;
    while (sPtr < ePtr) {
      if (*sPtr == NULL) {
        LPTSTR name = _tcsdup(prvPtr);
        mPrinters->AppendElement(name);
        PR_PL(("Printer Name:    %s\n", prvPtr));
        prvPtr = sPtr+1;
        count++;
      }
      sPtr++;
    }
    rv = NS_OK;
  }
  PR_PL(("-----------------------\n"));
#endif
  return rv;
}

Here is the caller graph for this function:

Definition at line 1139 of file nsDeviceContextSpecWin.cpp.

{
  // reallocate and get a new list each time it is asked for
  // this deletes the list and re-allocates them
  ReallocatePrinters();

  // any of these could only fail with an OUT_MEMORY_ERROR
  // PRINTER_ENUM_LOCAL should get the network printers on Win95
  nsresult rv = EnumerateNativePrinters();
  if (NS_FAILED(rv)) return rv;

  // get the name of the default printer
  LPTSTR defPrinterName;
  GetDefaultPrinterName(defPrinterName);

  // put the default printer at the beginning of list
  if (defPrinterName != nsnull) {
    for (PRInt32 i=0;i<mPrinters->Count();i++) {
      LPTSTR name = (LPTSTR)mPrinters->ElementAt(i);
      if (!_tcscmp(name, defPrinterName)) {
        if (i > 0) {
          LPTSTR ptr = (LPTSTR)mPrinters->ElementAt(0);
          mPrinters->ReplaceElementAt((void*)name, 0);
          mPrinters->ReplaceElementAt((void*)ptr, i);
        }
        break;
      }
    }
    free(defPrinterName);
  }

  // make sure we at least tried to get the printers
  if (!PrintersAreAllocated()) {
    PR_PL(("***** nsDeviceContextSpecWin::EnumeratePrinterList - Printers aren`t allocated\n"));
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 546 of file nsDeviceContextSpecB.cpp.

Here is the caller graph for this function:

Definition at line 556 of file nsDeviceContextSpecOS2.cpp.

{
  aDefaultPrinterName = nsnull;

  nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
  if (NS_FAILED(rv)) 
     return;

  if (GetNumPrinters() == 0)
     return;

  // the default printer is always index 0
  nsXPIDLCString printer;
  nsDeviceContextSpecOS2::PrnDlg.GetPrinter(0, getter_Copies(printer));

  nsAutoChar16Buffer printerName;
  PRInt32 printerNameLength;
  MultiByteToWideChar(0, printer, strlen(printer), printerName,
                      printerNameLength);
  aDefaultPrinterName = ToNewUnicode(nsDependentString(printerName.get()));

  GlobalPrinters::GetInstance()->FreeGlobalPrinters();
}

Here is the call graph for this function:

Definition at line 1110 of file nsDeviceContextSpecWin.cpp.

{
#ifndef WINCE
  aDefaultPrinterName = nsnull;
  TCHAR szDefaultPrinterName[1024];    
  DWORD status = GetProfileString("windows", "device", 0, szDefaultPrinterName, sizeof(szDefaultPrinterName)/sizeof(TCHAR));
  if (status > 0) {
    TCHAR comma = (TCHAR)',';
    LPTSTR sPtr = (LPTSTR)szDefaultPrinterName;
    while (*sPtr != comma && *sPtr != NULL) 
      sPtr++;
    if (*sPtr == comma) {
      *sPtr = NULL;
    }
    aDefaultPrinterName = _tcsdup(szDefaultPrinterName);
  } else {
    aDefaultPrinterName = _tcsdup("");
  }

  PR_PL(("DEFAULT PRINTER [%s]\n", aDefaultPrinterName));
#else
  aDefaultPrinterName = "UNKNOWN";
#endif
}

Definition at line 1374 of file nsDeviceContextSpecG.cpp.

{
  *aDefaultPrinterName = nsnull;
  
  PRBool allocate = (GlobalPrinters::GetInstance()->PrintersAreAllocated() == PR_FALSE);
  
  if (allocate) {
    nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
    if (NS_FAILED(rv)) {
      return;
    }
  }
  NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters");

  if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0)
    return;
  
  *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0));

  if (allocate) {  
    GlobalPrinters::GetInstance()->FreeGlobalPrinters();
  }  
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 55 of file nsDeviceContextSpecB.cpp.

{ return &mGlobalPrinters; }

Here is the caller graph for this function:

static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 65 of file nsDeviceContextSpecOS2.cpp.

{ return &mGlobalPrinters; }
static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 86 of file nsDeviceContextSpecWin.cpp.

{ return &mGlobalPrinters; }
static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 88 of file nsDeviceContextSpecXlib.cpp.

{ return &mGlobalPrinters; }
static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 88 of file nsDeviceContextSpecQt.cpp.

{ return &mGlobalPrinters; }
static GlobalPrinters* GlobalPrinters::GetInstance ( ) [inline, static]

Definition at line 88 of file nsDeviceContextSpecG.cpp.

{ return &mGlobalPrinters; }

Definition at line 92 of file nsDeviceContextSpecWin.cpp.

{ return mPrinters?(LPTSTR)mPrinters->ElementAt(aInx):nsnull; }

Definition at line 62 of file nsDeviceContextSpecB.cpp.

{ return mGlobalNumPrinters; }

Here is the caller graph for this function:

Definition at line 72 of file nsDeviceContextSpecOS2.cpp.

{ return mGlobalNumPrinters; }

Definition at line 95 of file nsDeviceContextSpecWin.cpp.

{ return mPrinters?mPrinters->Count():0; }

Definition at line 95 of file nsDeviceContextSpecQt.cpp.

{ return mGlobalNumPrinters; }

Definition at line 95 of file nsDeviceContextSpecXlib.cpp.

    { return mGlobalPrinterList ? mGlobalPrinterList->Count() : 0; }

Definition at line 95 of file nsDeviceContextSpecG.cpp.

    { return mGlobalPrinterList ? mGlobalPrinterList->Count() : 0; }

Definition at line 63 of file nsDeviceContextSpecB.cpp.

{ return mGlobalPrinterList->StringAt(aInx); }

Here is the caller graph for this function:

Definition at line 73 of file nsDeviceContextSpecOS2.cpp.

{ return mGlobalPrinterList->StringAt(aInx); }

Definition at line 96 of file nsDeviceContextSpecQt.cpp.

{ return mGlobalPrinterList->StringAt(aInx); }

Definition at line 97 of file nsDeviceContextSpecXlib.cpp.

{ return mGlobalPrinterList->StringAt(aInx); }

Definition at line 97 of file nsDeviceContextSpecG.cpp.

{ return mGlobalPrinterList->StringAt(aInx); }

Definition at line 485 of file nsDeviceContextSpecB.cpp.

{
  if (PrintersAreAllocated())
    return NS_OK;

  mGlobalNumPrinters = 0;

#ifdef USE_POSTSCRIPT
  mGlobalPrinterList = new nsStringArray();
  if (!mGlobalPrinterList) 
    return NS_ERROR_OUT_OF_MEMORY;

  /* add an entry for the default printer (see nsPostScriptObj.cpp) */
  mGlobalPrinterList->AppendString(
    nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default")));
  mGlobalNumPrinters++;

  /* get the list of printers */
  char *printerList = nsnull;
  
  /* the env var MOZILLA_PRINTER_LIST can "override" the prefs */
  printerList = PR_GetEnv("MOZILLA_PRINTER_LIST");
  
  if (!printerList) {
    nsresult rv;
    nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
    if (NS_SUCCEEDED(rv)) {
      (void) pPrefs->CopyCharPref("print.printer_list", &printerList);
    }
  }  

  if (printerList) {
    char *tok_lasts;
    char *name;
    
    /* PL_strtok_r() will modify the string - copy it! */
    printerList = strdup(printerList);
    if (!printerList)
      return NS_ERROR_OUT_OF_MEMORY;    

    for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; 
         name != nsnull ; 
         name = PL_strtok_r(nsnull, " ", &tok_lasts) )
    {
      mGlobalPrinterList->AppendString(
        nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + 
        nsString(NS_ConvertASCIItoUCS2(name)));
      mGlobalNumPrinters++;      
    }

    free(printerList);
  }
#endif /* USE_POSTSCRIPT */
      
  if (mGlobalNumPrinters == 0)
    return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; 

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file nsDeviceContextSpecB.cpp.

{ return mGlobalPrinterList != nsnull; }

Here is the caller graph for this function:

Definition at line 71 of file nsDeviceContextSpecOS2.cpp.

{ return mGlobalPrinterList != nsnull; }

Definition at line 91 of file nsDeviceContextSpecWin.cpp.

{ return mPrinters != nsnull; }

Definition at line 94 of file nsDeviceContextSpecXlib.cpp.

{ return mGlobalPrinterList != nsnull; }

Definition at line 94 of file nsDeviceContextSpecG.cpp.

{ return mGlobalPrinterList != nsnull; }

Definition at line 94 of file nsDeviceContextSpecQt.cpp.

{ return mGlobalPrinterList != nsnull; }

Definition at line 1052 of file nsDeviceContextSpecWin.cpp.

{
  if (PrintersAreAllocated()) {
    FreeGlobalPrinters();
  }
  mPrinters = new nsVoidArray();
  NS_ASSERTION(mPrinters, "Printers Array is NULL!");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int GlobalPrinters::mGlobalNumPrinters = 0 [static, protected]

Definition at line 70 of file nsDeviceContextSpecB.cpp.

Definition at line 81 of file nsDeviceContextSpecOS2.cpp.

nsStringArray * GlobalPrinters::mGlobalPrinterList = nsnull [static, protected]

Definition at line 69 of file nsDeviceContextSpecB.cpp.

Definition at line 68 of file nsDeviceContextSpecB.cpp.

nsVoidArray * GlobalPrinters::mPrinters = nsnull [static, protected]

Definition at line 103 of file nsDeviceContextSpecWin.cpp.


The documentation for this class was generated from the following files: