Commit 3e803415 authored by kaie%netscape.com's avatar kaie%netscape.com
Browse files

b=84947 New print dialog for Unix and OS/2

r=cls/rods/mkaply/pchen sr=roc+moz
Checking in for Roland.Mainz@informatik.med.uni-giessen.de
parent 807c7993
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
 *
 * Contributor(s):
 *   Don Cone <dcone@netscape.com>
 *   Jessica Blanco <jblanco@us.ibm.com>
 *
 *
 * Alternatively, the contents of this file may be used under the terms of
@@ -45,6 +46,8 @@
#include "nsFont.h"
%}

interface nsISimpleEnumerator;

/**
 * Native types
 */
@@ -171,6 +174,8 @@ interface nsIPrintOptions : nsISupports
  attribute long    paperSize;     /*  see page size consts */
  attribute long    orientation;   /*  see orientation consts */
  attribute wstring printCommand;
  attribute long    numCopies;
  attribute wstring printer;
  attribute boolean printToFile;
  attribute wstring toFileName;

@@ -188,6 +193,15 @@ interface nsIPrintOptions : nsISupports
  /* Purposely made this an "in" arg */
  [noscript] void GetDefaultFont(in nsNativeFontRef aMargin);

  /**
   * available Printers
   */
  nsISimpleEnumerator availablePrinters ();
  
  /**
   * display Printer Job Properties dialog
   */
   void displayJobProperties (in wstring aPrinter, out boolean aDisplayed);

  /**
   * Native data constants
@@ -195,5 +209,23 @@ interface nsIPrintOptions : nsISupports
  const short kNativeDataPrintRecord        = 0;

  [noscript] voidPtr GetNativeData(in short aDataType);
};

[scriptable, uuid(a6cf9128-15b3-11d2-932e-00805f8add32)]
interface nsIPrinterEnumerator : nsISupports
{
  /**
   * Return an array of the names of all installed printers.
   *
   * @param  aCount     returns number of printers returned
   * @param  aResult    returns array of names
   * @return void
   */
  void enumeratePrinters(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult);

  /*  takes printer selected and will display job properties dlg for that printer
   *  returns true if dialog displays
   */
  void displayPropertiesDlg(in wstring aPrinter);
};
+3 −0
Original line number Diff line number Diff line
@@ -103,5 +103,8 @@
{ 0x30a3b080, 0x4867, 0x11d4, \
{ 0xa8, 0x56, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } }

#define NS_PRINTER_ENUMERATOR_CID \
{ 0xa6cf9129, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }

#endif
+13 −1
Original line number Diff line number Diff line
@@ -72,6 +72,13 @@ ifneq (gtk,$(MOZ_GFX_TOOLKIT))
INACTIVE_COMPONENT = 1
endif

ifdef MOZ_ENABLE_XPRINT
XPU_LCSRCS	 = xprintutil.c
CSRCS           += $(XPU_LCSRCS)
endif

GARBAGE         += $(XPU_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))

include $(topsrcdir)/config/rules.mk

EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS)
@@ -105,7 +112,9 @@ endif
endif

ifdef MOZ_ENABLE_XPRINT
DEFINES		+= -DUSE_XPRINT
DEFINES         += -DUSE_XPRINT -DUSE_MOZILLA_TYPES
INCLUDES	+= -I$(srcdir)/../xprint
EXTRA_DSO_LDOPTS += $(MOZ_XPRINT_LDFLAGS)
endif

LOCAL_INCLUDES	= \
@@ -113,3 +122,6 @@ LOCAL_INCLUDES = \
		-I$(srcdir)/.. \
		$(NULL)

export:: $(addprefix $(srcdir)/../xprint/,$(XPU_LCSRCS))
	$(INSTALL) $^ .
        
+226 −30
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
#include "nsReadableUtils.h"
#include "nsGfxCIID.h"

#include "nsIPref.h"
@@ -54,8 +55,15 @@
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"

#ifdef USE_XPRINT
#include "xprintutil.h"
#endif /* USE_XPRINT */

static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);

nsStringArray* nsDeviceContextSpecGTK::globalPrinterList = nsnull;
int nsDeviceContextSpecGTK::globalNumPrinters = 0;

/** -------------------------------------------------------
 *  Construct the nsDeviceContextSpecGTK
 *  @update   dc 12/02/98
@@ -79,10 +87,6 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
static NS_DEFINE_IID(kIDeviceContextSpecXPIID, NS_IDEVICE_CONTEXT_SPEC_XP_IID);
#endif

#if 0
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK, nsIDeviceContextSpec)
#endif

NS_IMETHODIMP nsDeviceContextSpecGTK :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
  if (nsnull == aInstancePtr)
@@ -131,6 +135,84 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: QueryInterface(REFNSIID aIID, void** aIn
NS_IMPL_ADDREF(nsDeviceContextSpecGTK)
NS_IMPL_RELEASE(nsDeviceContextSpecGTK)


int nsDeviceContextSpecGTK::InitializeGlobalPrinters ()
{
  globalNumPrinters = 0;
  globalPrinterList = new nsStringArray();
  if (!globalPrinterList) 
    return NS_ERROR_OUT_OF_MEMORY;
      
#ifdef USE_XPRINT   
  XPPrinterList plist = XpuGetPrinterList(nsnull, &globalNumPrinters);
  
  if (plist && (globalNumPrinters > 0))
  {  
    int i;
    for(  i = 0 ; i < globalNumPrinters ; i++ )
    {
      globalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name)));
    }
    
    XpuFreePrinterList(plist);
  }  
#endif /* USE_XPRINT */

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

  /* 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) )
    {
      globalPrinterList->AppendString(
        nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + 
        nsString(NS_ConvertASCIItoUCS2(name)));
      globalNumPrinters++;      
    }
    
    free(printerList);
  }
      
  if (globalNumPrinters == 0)
    return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE; 

  return NS_OK;
}

void nsDeviceContextSpecGTK::FreeGlobalPrinters()
{
  delete globalPrinterList;
  globalPrinterList = nsnull;
  globalNumPrinters = 0;
}


/** -------------------------------------------------------
 *  Initialize the nsDeviceContextSpecGTK
 *  @update   dc 2/15/98
@@ -162,7 +244,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
    PRBool isOn;
    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
    nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
    if (NS_SUCCEEDED(rv) && pPrefs) {
    if (NS_SUCCEEDED(rv)) {
      (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
    }
  }
@@ -178,13 +260,21 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
  PRInt32    fromPage       = 1;
  PRInt32    toPage         = 1;
  PRUnichar *command        = nsnull;
  PRInt32    copies         = 1;
  PRUnichar *printer        = nsnull;
  PRUnichar *printfile      = nsnull;
  double     dleft          = 0.5;
  double     dright         = 0.5;
  double     dtop           = 0.5;
  double     dbottom        = 0.5; 

  if (PR_FALSE == aQuiet ) {
  if( !globalPrinterList )
    if (InitializeGlobalPrinters())
       return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAIULABLE;
  if( globalNumPrinters && !globalPrinterList->Count() ) 
     return NS_ERROR_OUT_OF_MEMORY;

  if (!aQuiet ) {
    rv = NS_ERROR_FAILURE;
    nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));

@@ -198,13 +288,9 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)

      nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
      if (wwatch) {

        nsCOMPtr<nsIDOMWindowInternal> parent;
        nsCOMPtr<nsIDOMWindow> active;
        wwatch->GetActiveWindow(getter_AddRefs(active));      
        if (active) {
          active->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(parent));
        }
        nsCOMPtr<nsIDOMWindowInternal> parent = do_QueryInterface(active);

        nsCOMPtr<nsIDOMWindow> newWindow;
        rv = wwatch->OpenWindow(parent, "chrome://global/content/printdialog.xul",
@@ -227,8 +313,11 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
    canPrint = PR_TRUE;
  }
  
  FreeGlobalPrinters();

  if (canPrint) {
    if (printService) {
      printService->GetPrinter(&printer);
      printService->GetPrintReversed(&reversed);
      printService->GetPrintInColor(&color);
      printService->GetPaperSize(&paper_size);
@@ -239,6 +328,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
      printService->GetPrintToFile(&tofile);
      printService->GetStartPageRange(&fromPage);
      printService->GetEndPageRange(&toPage);
      printService->GetNumCopies(&copies);
      printService->GetMarginTop(&dtop);
      printService->GetMarginLeft(&dleft);
      printService->GetMarginBottom(&dbottom);
@@ -249,6 +339,8 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
        strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get());  
        strcpy(mPrData.path,    NS_ConvertUCS2toUTF8(printfile).get());
      }
      if (printer != nsnull) 
        strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get());        
#ifdef DEBUG_rods
      printf("margins:       %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright);
      printf("printRange     %d\n", printRange);
@@ -261,7 +353,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
      // as I need to make the default be "print" instead of "lpr" for OpenVMS.
      strcpy(mPrData.command, "print");
#else
      strcpy(mPrData.command, "lpr");
      strcpy(mPrData.command, "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}");
#endif /* VMS */
    }

@@ -274,6 +366,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
    mPrData.size      = paper_size;
    mPrData.orientation = orientation;
    mPrData.toPrinter = !tofile;
    mPrData.copies = copies;

    // PWD, HOME, or fail 
    
@@ -287,6 +380,16 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
      else
        return NS_ERROR_FAILURE;
    }
    
#ifdef NOT_IMPLEMENTED_YET
    if (globalNumPrinters) {
       for(int i = 0; (i < globalNumPrinters) && !mQueue; i++) {
          if (!(globalPrinterList->StringAt(i)->CompareWithConversion(mPrData.printer, TRUE, -1)))
             mQueue = PrnDlg.SetPrinterQueue(i);
       }
    }
#endif /* NOT_IMPLEMENTED_YET */
    
    if (command != nsnull) {
      nsMemory::Free(command);
    }
@@ -306,6 +409,18 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetToPrinter( PRBool &aToPrinter )
  return NS_OK;
}

NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrinter ( char **aPrinter )
{
   *aPrinter = &mPrData.printer[0];
   return NS_OK;
}

NS_IMETHODIMP nsDeviceContextSpecGTK::GetCopies ( int &aCopies )
{
   aCopies = mPrData.copies;
   return NS_OK;
}

NS_IMETHODIMP nsDeviceContextSpecGTK :: GetFirstPageFirst ( PRBool &aFpf )      
{
  aFpf = mPrData.fpf;
@@ -404,26 +519,107 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetUserCancelled( PRBool &aCancel )

NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrintMethod(PrintMethod &aMethod)
{
  nsresult rv;
  nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv) && pPrefs) {
    PRInt32 method = (PRInt32)pmAuto;
    (void) pPrefs->GetIntPref("print.print_method", &method);
    aMethod = (PrintMethod)method;
    if (aMethod == pmAuto)
      aMethod = NS_DEFAULT_PRINT_METHOD;
  } else {
    aMethod = NS_DEFAULT_PRINT_METHOD;
  }
  /* printer names for the PostScript module alwas start with 
   * the NS_POSTSCRIPT_DRIVER_NAME string */
  if (strncmp(mPrData.printer, NS_POSTSCRIPT_DRIVER_NAME, 
              NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0)
    aMethod = pmXprint;
  else
    aMethod = pmPostScript;
    
  return NS_OK;
}

/** -------------------------------------------------------
 * Closes the printmanager if it is open.
 *  @update   dc 2/15/98
 */
NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager()
{
  return NS_OK;
}


//  Printer Enumerator
nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
{
  NS_INIT_REFCNT();
}

NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator)

NS_IMETHODIMP nsPrinterEnumeratorGTK::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult)
{
  if (aCount) 
    *aCount = 0;
  else 
    return NS_ERROR_NULL_POINTER;
  
  if (aResult) 
    *aResult = nsnull;
  else 
    return NS_ERROR_NULL_POINTER;
  

  PRUnichar** array = (PRUnichar**) nsMemory::Alloc(nsDeviceContextSpecGTK::globalNumPrinters * sizeof(PRUnichar*));
  if (!array && nsDeviceContextSpecGTK::globalNumPrinters) 
    return NS_ERROR_OUT_OF_MEMORY;
  
  int count = 0;
  while( count < nsDeviceContextSpecGTK::globalNumPrinters )
  {
    PRUnichar *str = ToNewUnicode(*nsDeviceContextSpecGTK::globalPrinterList->StringAt(count));

    if (!str) {
      for (int i = count - 1; i >= 0; i--) 
        nsMemory::Free(array[i]);
      
      nsMemory::Free(array);
      return NS_ERROR_OUT_OF_MEMORY;
    }
    array[count++] = str;
    
  }
  *aCount = count;
  *aResult = array;

  return NS_OK;
}

NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter)
{
  nsresult rv = NS_ERROR_FAILURE;
  
  /* fixme: We simply ignore the |aPrinter| argument here
   * We should get the supported printer attributes from the printer and 
   * populate the print job options dialog with these data instead of using 
   * the "default set" here.
   * However, this requires changes on all platforms and is another big chunk
   * of patches ... ;-(
   */

  nsCOMPtr<nsIPrintOptions> printService(do_GetService(kPrintOptionsCID, &rv));

  rv = NS_ERROR_FAILURE;
  nsCOMPtr<nsIDialogParamBlock> ioParamBlock(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));

  nsCOMPtr<nsISupportsInterfacePointer> paramBlockWrapper;
  if (ioParamBlock)
    paramBlockWrapper = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);

  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/printjoboptions.xul",
                    "_blank", "chrome,modal", paramBlockWrapper,
                    getter_AddRefs(newWindow));
    }
  }

  return rv;
}
+29 −14
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@
#define nsDeviceContextSpecG_h___

#include "nsIDeviceContextSpec.h"
#include "nsDeviceContextSpecG.h"
#include "nsIPrintOptions.h"
#include "nsVoidArray.h"
#include "nsIDeviceContextSpecPS.h"
#ifdef USE_XPRINT
#include "nsIDeviceContextSpecXPrint.h"
@@ -50,17 +51,11 @@

typedef enum
{
  pmAuto = 0, /* default */
  pmInvalid = 0,
  pmXprint,
  pmPostScript
} PrintMethod;
 
/* make Xprint the default print system if user/admin has set the XPSERVERLIST"
 * env var. See Xprt config README (/usr/openwin/server/etc/XpConfig/README) 
 * for details.
 */
#define NS_DEFAULT_PRINT_METHOD ((PR_GetEnv("XPSERVERLIST")!=nsnull)?(pmXprint):(pmPostScript))

class nsDeviceContextSpecGTK : public nsIDeviceContextSpec ,
                                      public nsIDeviceContextSpecPS
#ifdef USE_XPRINT
@@ -100,6 +95,10 @@ public:

  NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); 

  NS_IMETHOD GetPrinter ( char **aPrinter );

  NS_IMETHOD GetCopies ( int &aCopies );

  NS_IMETHOD GetFirstPageFirst ( PRBool &aFpf );     

  NS_IMETHOD GetGrayscale( PRBool &aGrayscale );   
@@ -125,17 +124,33 @@ public:
  NS_IMETHOD GetUserCancelled( PRBool &aCancel );      

  NS_IMETHOD GetPrintMethod(PrintMethod &aMethod ); 
protected:

/**
 * Destuct a nsDeviceContextSpecMac, this will release the printrecord
 * @update  dc 2/16/98
 */
  virtual ~nsDeviceContextSpecGTK();
  
  static nsStringArray *globalPrinterList;
  static int globalNumPrinters;
  int InitializeGlobalPrinters();
  void FreeGlobalPrinters();
protected:

  UnixPrData mPrData;
};

//-------------------------------------------------------------------------
// Printer Enumerator
//-------------------------------------------------------------------------
class nsPrinterEnumeratorGTK : public nsIPrinterEnumerator
{
public:
  nsPrinterEnumeratorGTK();
  NS_DECL_ISUPPORTS
  NS_DECL_NSIPRINTERENUMERATOR

protected:
};

#endif
#endif /* !nsDeviceContextSpecG_h___ */
Loading