gfx/src/xlib/nsDeviceContextSpecXlib.cpp - Revision 1.17

There were 16 changes made.
Legend
   Added lines
   Changed lines
   Removed lines

gfx/src/xlib/nsDeviceContextSpecXlib.cpp,1.17
.
Disk File
Skipping to line 36. 
 * the terms of any one of the NPL, the GPL or the LGPL.
.
 * the terms of any one of the NPL, the GPL or the LGPL.
 *
.
 *
 * ***** END LICENSE BLOCK ***** */
.
 * ***** END LICENSE BLOCK ***** */
 
.
 
#include "nsDeviceContextSpecXlib.h"
.
#include "nsDeviceContextSpecXlib.h"
 
.
 
#include "nsCOMPtr.h"
.
 
#include "nsIServiceManager.h"
.
 
#include "nsIPrintOptions.h"
.
 
#include "nsReadableUtils.h"
.
 
#include "nsGfxCIID.h"
.
 
 
.
 
#include "nsIPref.h"
.
#include "nsIPref.h"
#include "prenv.h" /* for PR_GetEnv */
.
#include "prenv.h" /* for PR_GetEnv */
 
.
 
#include "nsIDOMWindowInternal.h"
.
#include "nsIDOMWindowInternal.h"
#include "nsIServiceManager.h"
.
#include "nsIServiceManager.h"
Skipping to line 48. 
#include "nsISupportsPrimitives.h"
.
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
.
#include "nsIWindowWatcher.h"
 
.
 
 
.
#include "nsReadableUtils.h"
 
.
#include "nsISupportsArray.h"
 
.
 
#ifdef USE_XPRINT
.
#ifdef USE_XPRINT
#include "xprintutil.h"
.
#include "xprintutil.h"
#endif /* USE_XPRINT */
.
#endif /* USE_XPRINT */
 
.
 
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
.
 
 
.
 
nsStringArray* nsDeviceContextSpecXlib::globalPrinterList = nsnull;
.
nsStringArray* nsDeviceContextSpecXlib::globalPrinterList = nsnull;
int nsDeviceContextSpecXlib::globalNumPrinters = 0;
.
int nsDeviceContextSpecXlib::globalNumPrinters = 0;
 
.
 
nsDeviceContextSpecXlib::nsDeviceContextSpecXlib()
.
nsDeviceContextSpecXlib::nsDeviceContextSpecXlib()
{
.
{
Skipping to line 195. 
  delete globalPrinterList;
.
  delete globalPrinterList;
  globalPrinterList = nsnull;
.
  globalPrinterList = nsnull;
  globalNumPrinters = 0;
.
  globalNumPrinters = 0;
}
.
}
 
.
 
 
.
/** -------------------------------------------------------
 
.
 */
 
.
static nsresult DisplayXPDialog(nsIPrintSettings* aPS,
 
.
                                const char* aChromeURL, 
 
.
                                PRBool& aClickedOK)
 
.
{
 
.
  NS_ASSERTION(aPS, "Must have a print settings!");
 
.
 
 
.
  aClickedOK = PR_FALSE;
 
.
  nsresult rv = NS_ERROR_FAILURE;
 
.
 
 
.
  // create a nsISupportsArray of the parameters 
 
.
  // being passed to the window
 
.
  nsCOMPtr<nsISupportsArray> array;
 
.
  NS_NewISupportsArray(getter_AddRefs(array));
 
.
  if (!array) return NS_ERROR_FAILURE;
 
.
 
 
.
  nsCOMPtr<nsIPrintSettings> ps = aPS;
 
.
  nsCOMPtr<nsISupports> psSupports(do_QueryInterface(ps));
 
.
  NS_ASSERTION(psSupports, "PrintSettings must be a supports");
 
.
  array->AppendElement(psSupports);
 
.
 
 
 
.
  nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/e
mbedcomp/dialogparam;1"));
 
.
  if (ioParamBlock) {
 
.
    ioParamBlock->SetInt(0, 0);
 
.
    nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(ioParamBlock));
 
.
    NS_ASSERTION(blkSupps, "IOBlk must be a supports");
 
.
 
 
.
    array->AppendElement(blkSupps);
 
.
    nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
 
.
    NS_ASSERTION(array, "array must be a supports");
 
.
 
 
 
.
    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/wi
ndow-watcher;1"));
 
.
    if (wwatch) {
 
.
      nsCOMPtr<nsIDOMWindow> active;
 
.
      wwatch->GetActiveWindow(getter_AddRefs(active));    
 
.
      nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
 
.
 
 
.
      nsCOMPtr<nsIDOMWindow> newWindow;
 
.
      rv = wwatch->OpenWindow(parent, aChromeURL,
 
.
            "_blank", "chrome,modal,centerscreen", array,
 
.
            getter_AddRefs(newWindow));
 
.
    }
 
.
  }
 
.
 
 
.
  if (NS_SUCCEEDED(rv)) {
 
.
    PRInt32 buttonPressed = 0;
 
.
    ioParamBlock->GetInt(0, &buttonPressed);
 
.
    if (buttonPressed == 1) {
 
.
      aClickedOK = PR_TRUE;
 
.
    } else {
 
.
      rv = NS_ERROR_ABORT;
 
.
    }
 
.
  } else {
 
.
    rv = NS_ERROR_ABORT;
 
.
  }
 
.
  return rv;
 
.
}
 
.
 
/** -------------------------------------------------------
.
/** -------------------------------------------------------
 *  Initialize the nsDeviceContextSpecGTK
.
 *  Initialize the nsDeviceContextSpecGTK
 *  @update   dc 2/15/98
.
 *  @update   dc 2/15/98
 *  @update   syd 3/2/99
.
 *  @update   syd 3/2/99
Skipping to line 273. 
 *   file:     mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
.
 *   file:     mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
 *   function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
.
 *   function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
 * 
.
 * 
 * ** Please update the other toolkits when changing this function.
.
 * ** Please update the other toolkits when changing this function.
 */
.
 */
NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
 
.
NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings* aPS, PRBool aQui
et)
{
.
{
  nsresult rv = NS_ERROR_FAILURE;
.
  nsresult rv = NS_ERROR_FAILURE;
 
.
 
  nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv))
;
.
  NS_ASSERTION(nsnull != aPS, "No print settings.");
 
  NS_ASSERTION(nsnull != printService, "No print service.");
.
 
  
.
  
  // if there is a current selection then enable the "Selection" radio button
.
  // if there is a current selection then enable the "Selection" radio button
  if (NS_SUCCEEDED(rv) && printService) {
.
  if (aPS != nsnull) {
    PRBool isOn;
.
    PRBool isOn;
    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, &isOn);
.
    aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
 
    nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
.
    nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
    if (NS_SUCCEEDED(rv)) {
.
    if (NS_SUCCEEDED(rv)) {
      (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
.
      (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
    }
.
    }
  }
.
  }
Skipping to line 294. 
  char      *path;
.
  char      *path;
  PRBool     canPrint       = PR_FALSE;
.
  PRBool     canPrint       = PR_FALSE;
  PRBool     reversed       = PR_FALSE;
.
  PRBool     reversed       = PR_FALSE;
  PRBool     color          = PR_FALSE;
.
  PRBool     color          = PR_FALSE;
  PRBool     tofile         = PR_FALSE;
.
  PRBool     tofile         = PR_FALSE;
  PRInt16    printRange     = nsIPrintOptions::kRangeAllPages;
.
  PRInt16    printRange     = nsIPrintSettings::kRangeAllPages;
  PRInt32    paper_size     = NS_LETTER_SIZE;
.
  PRInt32    paper_size     = NS_LETTER_SIZE;
  PRInt32    orientation    = NS_PORTRAIT;
.
  PRInt32    orientation    = NS_PORTRAIT;
  PRInt32    fromPage       = 1;
.
  PRInt32    fromPage       = 1;
  PRInt32    toPage         = 1;
.
  PRInt32    toPage         = 1;
  PRUnichar *command        = nsnull;
.
  PRUnichar *command        = nsnull;
Skipping to line 315. 
       return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
.
       return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
  if( globalNumPrinters && !globalPrinterList->Count() ) 
.
  if( globalNumPrinters && !globalPrinterList->Count() ) 
     return NS_ERROR_OUT_OF_MEMORY;
.
     return NS_ERROR_OUT_OF_MEMORY;
 
.
 
  if (!aQuiet ) {
.
  if (!aQuiet ) {
    rv = NS_ERROR_FAILURE;
.
    rv = DisplayXPDialog(aPS, 
    nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org
/embedcomp/dialogparam;1"));
.
                         "chrome://global/content/printdialog.xul", canPrint);
    
 
.
 
    nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
.
 
    if (ioParamBlock)
.
 
      paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONT
RACTID);
.
 
 
 
.
 
    if (paramBlockWrapper) {
.
 
      paramBlockWrapper->SetData(ioParamBlock);
.
 
      paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock));
.
 
 
.
 
      nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/
window-watcher;1"));
.
 
 
      if (wwatch) {
.
 
        nsCOMPtr<nsIDOMWindow> active;
.
 
        wwatch->GetActiveWindow(getter_AddRefs(active));      
.
 
        nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
.
 
 
.
 
        nsCOMPtr<nsIDOMWindow> newWindow;
.
 
        rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.x
ul",
.
 
 
                      "_blank", "chrome,modal", paramBlockWrapper,
.
 
                      getter_AddRefs(newWindow));
.
 
      }
.
 
    }
.
 
    if (NS_SUCCEEDED(rv)) {
.
 
      PRInt32 buttonPressed = 0;
.
 
      ioParamBlock->GetInt(0, &buttonPressed);
.
 
      if (buttonPressed == 0) {
.
 
        canPrint = PR_TRUE;
.
 
      }
.
 
      else {
.
 
        rv = NS_ERROR_ABORT;
.
 
      }
.
 
    }
.
 
  }
.
  }
  else {
.
  else {
    canPrint = PR_TRUE;
.
    canPrint = PR_TRUE;
  }
.
  }
  
.
  
Skipping to line 328. 
 
.
 
  if (canPrint) {
.
  if (canPrint) {
    if (printService) {
.
    if (aPS != nsnull) {
      printService->GetPrinter(&printer);
.
      aPS->GetPrinterName(&printer);
      printService->GetPrintReversed(&reversed);
.
      aPS->GetPrintReversed(&reversed);
      printService->GetPrintInColor(&color);
.
      aPS->GetPrintInColor(&color);
      printService->GetPaperSize(&paper_size);
.
      aPS->GetPaperSize(&paper_size);
      printService->GetOrientation(&orientation);
.
      aPS->GetOrientation(&orientation);
      printService->GetPrintCommand(&command);
.
      aPS->GetPrintCommand(&command);
      printService->GetPrintRange(&printRange);
.
      aPS->GetPrintRange(&printRange);
      printService->GetToFileName(&printfile);
.
      aPS->GetToFileName(&printfile);
      printService->GetPrintToFile(&tofile);
.
      aPS->GetPrintToFile(&tofile);
      printService->GetStartPageRange(&fromPage);
.
      aPS->GetStartPageRange(&fromPage);
      printService->GetEndPageRange(&toPage);
.
      aPS->GetEndPageRange(&toPage);
      printService->GetNumCopies(&copies);
.
      aPS->GetNumCopies(&copies);
      printService->GetMarginTop(&dtop);
.
      aPS->GetMarginTop(&dtop);
      printService->GetMarginLeft(&dleft);
.
      aPS->GetMarginLeft(&dleft);
      printService->GetMarginBottom(&dbottom);
.
      aPS->GetMarginBottom(&dbottom);
      printService->GetMarginRight(&dright);
.
      aPS->GetMarginRight(&dright);
 
.
 
      if (command != nsnull && printfile != nsnull) {
.
      if (command != nsnull && printfile != nsnull) {
        // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446)
.
        // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446)
        strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get());  
.
        strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get());  
        strcpy(mPrData.path,    NS_ConvertUCS2toUTF8(printfile).get());
.
        strcpy(mPrData.path,    NS_ConvertUCS2toUTF8(printfile).get());
Skipping to line 418. 
{
.
{
  aToPrinter = mPrData.toPrinter;
.
  aToPrinter = mPrData.toPrinter;
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinter ( char **aPrinter )
.
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinterName ( char **aPrinter )
{
.
{
   *aPrinter = &mPrData.printer[0];
.
   *aPrinter = &mPrData.printer[0];
   return NS_OK;
.
   return NS_OK;
}
.
}
 
.
 
Skipping to line 592. 
  *aResult = array;
.
  *aResult = array;
 
.
 
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *a
Printer)
.
NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *a
Printer, nsIPrintSettings *aPrintSettings)
{
.
{
  nsresult rv = NS_ERROR_FAILURE;
.
 
  
.
 
  /* fixme: We simply ignore the |aPrinter| argument here
.
  /* fixme: We simply ignore the |aPrinter| argument here
   * We should get the supported printer attributes from the printer and 
.
   * We should get the supported printer attributes from the printer and 
   * populate the print job options dialog with these data instead of using 
.
   * populate the print job options dialog with these data instead of using 
   * the "default set" here.
.
   * the "default set" here.
   * However, this requires changes on all platforms and is another big chunk
.
   * However, this requires changes on all platforms and is another big chunk
Skipping to line 605. 
   */
.
   */
 
.
 
  nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv))
;
.
  PRBool pressedOK;
 
 
.
  return DisplayXPDialog(aPrintSettings,
 
.
                         "chrome://global/content/printjoboptions.xul", 
 
.
                         pressedOK);
 
.
 
  rv = NS_ERROR_FAILURE;
.
 
  nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/e
mbedcomp/dialogparam;1"));
.
 
 
 
.
 
  nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
.
 
  if (ioParamBlock)
.
 
    paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRA
CTID);
.
 
 
 
.
 
  if (paramBlockWrapper) {
.
 
    paramBlockWrapper->SetData(ioParamBlock);
.
 
    paramBlockWrapper->SetDataIID(&NS_GET_IID(nsIDialogParamBlock));
.
 
 
.
 
    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/wi
ndow-watcher;1"));
.
 
 
    if (wwatch) {
.
 
      nsCOMPtr<nsIDOMWindow> active;
.
 
      wwatch->GetActiveWindow(getter_AddRefs(active));
.
 
      nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);
.
 
 
.
 
      nsCOMPtr<nsIDOMWindow> newWindow;
.
 
      rv = wwatch->OpenWindow(parent, "chrome://global/content/printjoboptions
.xul",
.
 
 
                    "_blank", "chrome,modal", paramBlockWrapper,
.
 
                    getter_AddRefs(newWindow));
.
 
    }
.
 
  }
.
 
 
.
 
  return rv;
.
 
}
.
}
 
.