gfx/src/gtk/nsDeviceContextSpecG.cpp - Revision 1.34

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

gfx/src/gtk/nsDeviceContextSpecG.cpp,1.34
.
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 "nsDeviceContextSpecG.h"
.
#include "nsDeviceContextSpecG.h"
 
.
 
#include "nsCOMPtr.h"
.
 
#include "nsIServiceManager.h"
.
 
#include "nsIPrintOptions.h"
.
 
#include "nsReadableUtils.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 "nsIDOMWindow.h"
.
#include "nsIDOMWindow.h"
Skipping to line 49. 
#include "nsIDialogParamBlock.h"
.
#include "nsIDialogParamBlock.h"
#include "nsISupportsPrimitives.h"
.
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
.
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
.
#include "nsIDOMWindowInternal.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* nsDeviceContextSpecGTK::globalPrinterList = nsnull;
.
nsStringArray* nsDeviceContextSpecGTK::globalPrinterList = nsnull;
int nsDeviceContextSpecGTK::globalNumPrinters = 0;
.
int nsDeviceContextSpecGTK::globalNumPrinters = 0;
 
.
 
/** -------------------------------------------------------
.
/** -------------------------------------------------------
 *  Construct the nsDeviceContextSpecGTK
.
 *  Construct the nsDeviceContextSpecGTK
Skipping to line 206. 
  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 284. 
 *   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 nsDeviceContextSpecGTK::Init(PRBool aQuiet)
 
.
NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings* aPS, PRBool aQuie
t)
{
.
{
  nsresult rv = NS_ERROR_FAILURE;
.
  nsresult rv = NS_ERROR_FAILURE;
 
.
 
  nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv))
;
.
  mPrintSettings = aPS;
 
  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 (mPrintSettings) {
    PRBool isOn;
.
    PRBool isOn;
    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, &isOn);
.
    mPrintSettings->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelect
ionRB, &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 326. 
       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(mPrintSettings, 
    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 339. 
 
.
 
  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);
 
.
 
 
.
#ifdef DEBUG_rods
 
.
      {
 
.
        nsString str; str =  command;
 
.
        char* s = ToNewCString(str);
 
.
        printf("command   %s\n", s);
 
.
        nsMemory::Free(s);
 
.
        str = printfile;
 
.
        s = ToNewCString(str);
 
.
        printf("printfile %s\n", s);
 
.
        nsMemory::Free(s);
 
.
        str = printer;
 
.
        s = ToNewCString(str);
 
.
        printf("printer   %s\n", s);
 
.
        nsMemory::Free(s);
 
.
      }
 
.
#endif /* DEBUG_rods */
 
.
 
      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 432. 
    if (command != nsnull) {
.
    if (command != nsnull) {
      nsMemory::Free(command);
.
      nsMemory::Free(command);
    }
.
    }
    if (printfile != nsnull) {
.
    if (printfile != nsnull) {
      nsMemory::Free(printfile);
.
      nsMemory::Free(printfile);
    }
.
    }
 
.
 
    return NS_OK;
.
    return NS_OK;
  }
.
  }
 
.
 
  return rv;
.
  return rv;
}
.
}
Skipping to line 445. 
{
.
{
  aToPrinter = mPrData.toPrinter;
.
  aToPrinter = mPrData.toPrinter;
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinter ( char **aPrinter )
.
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinterName ( char **aPrinter )
{
.
{
   *aPrinter = &mPrData.printer[0];
.
   *aPrinter = &mPrData.printer[0];
   return NS_OK;
.
   return NS_OK;
}
.
}
 
.
 
Skipping to line 570. 
 
.
 
NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager()
.
NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager()
{
.
{
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
 
.
 
//  Printer Enumerator
.
//  Printer Enumerator
nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
.
nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
{
.
{
  NS_INIT_REFCNT();
.
  NS_INIT_REFCNT();
}
.
}
Skipping to line 617. 
  *aResult = array;
.
  *aResult = array;
 
.
 
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aP
rinter)
.
NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aP
rinter, 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 630. 
   */
.
   */
 
.
 
  nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv))
;
.
  PRBool pressedOK;
 
 
.
  return DisplayXPDialog(aPrintSettings,
  rv = NS_ERROR_FAILURE;
.
                         "chrome://global/content/printjoboptions.xul", 
  nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/e
mbedcomp/dialogparam;1"));
.
                         pressedOK);
 
 
.
 
  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;
.
 
}
.
}
 
.