зеркало из https://github.com/mozilla/pjs.git
Bug 193001 - "Use gnome's native print dialog" [p=ventnor.bugzilla@yahoo.com.au (Michael Ventnor) r+sr=roc a1.9=schrep]
This commit is contained in:
Родитель
a9edc0f6e2
Коммит
e5354271fd
|
@ -250,6 +250,9 @@ gtk/gtkinvisible.h
|
|||
gtk/gtkmain.h
|
||||
gtk/gtkmessagedialog.h
|
||||
gtk/gtkobject.h
|
||||
gtk/gtkprinter.h
|
||||
gtk/gtkprintjob.h
|
||||
gtk/gtkprintunixdialog.h
|
||||
gtk/gtkprivate.h
|
||||
gtk/gtkselection.h
|
||||
gtk/gtksignal.h
|
||||
|
|
|
@ -4597,7 +4597,7 @@ fi
|
|||
if test "$COMPILE_ENVIRONMENT"; then
|
||||
if test "$MOZ_ENABLE_GTK2"
|
||||
then
|
||||
PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= $GTK2_VERSION gdk-x11-2.0 glib-2.0 gobject-2.0)
|
||||
PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= $GTK2_VERSION gtk+-unix-print-2.0 gdk-x11-2.0 glib-2.0 gobject-2.0)
|
||||
fi
|
||||
fi # COMPILE_ENVIRONMENT
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "nsISupportsUtils.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIPrintDialogService.h"
|
||||
|
||||
// Printing Progress Includes
|
||||
#include "nsPrintProgress.h"
|
||||
|
@ -109,6 +110,13 @@ nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrin
|
|||
NS_ENSURE_ARG(webBrowserPrint);
|
||||
NS_ENSURE_ARG(printSettings);
|
||||
|
||||
// Try to access a component dialog
|
||||
nsCOMPtr<nsIPrintDialogService> dlgPrint(do_GetService(
|
||||
NS_PRINTDIALOGSERVICE_CONTRACTID));
|
||||
if (dlgPrint)
|
||||
return dlgPrint->Show(printSettings);
|
||||
|
||||
// Show the built-in dialog instead
|
||||
ParamBlock block;
|
||||
nsresult rv = block.Init();
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -177,6 +185,12 @@ nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *p
|
|||
{
|
||||
NS_ENSURE_ARG(printSettings);
|
||||
|
||||
// Try to access a component dialog
|
||||
nsCOMPtr<nsIPrintDialogService> dlgPrint(do_GetService(
|
||||
NS_PRINTDIALOGSERVICE_CONTRACTID));
|
||||
if (dlgPrint)
|
||||
return dlgPrint->ShowPageSetup(printSettings);
|
||||
|
||||
ParamBlock block;
|
||||
nsresult rv = block.Init();
|
||||
if (NS_FAILED(rv))
|
||||
|
|
|
@ -597,6 +597,8 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
|
|||
// are telling GFX we want to print silent
|
||||
printSilently = PR_TRUE;
|
||||
}
|
||||
// XXX Some platforms allow the user to change the ShrinkToFit option so change it here too
|
||||
mPrt->mPrintSettings->GetShrinkToFit(&mPrt->mShrinkToFit);
|
||||
} else {
|
||||
rv = NS_ERROR_GFX_NO_PRINTROMPTSERVICE;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
printTitle=Print
|
||||
optionsTabLabel=Options
|
||||
printFramesTitle=Print Frames
|
||||
|
||||
# TRANSLATOR NOTE: For radio button labels and check button labels, an underscore _
|
||||
# before a character will turn that character into an accesskey.
|
||||
# e.g. "_As laid out" will make A the accesskey.
|
||||
|
||||
asLaidOut=_As Laid Out on the Screen
|
||||
selectedFrame=The _Selected Frame
|
||||
separateFrames=Each Frame on Separate _Pages
|
||||
shrinkToFit=Ignore Scaling and S_hrink To Fit Page Width
|
||||
selectionOnly=Print Selection _Only
|
||||
printBGOptions=Print Backgrounds
|
||||
printBGColors=Print Background _Colors
|
||||
printBGImages=Print Background I_mages
|
||||
headerFooter=Header and Footer
|
||||
left=Left
|
||||
center=Center
|
||||
right=Right
|
||||
headerFooterBlank=--blank--
|
||||
headerFooterTitle=Title
|
||||
headerFooterURL=URL
|
||||
headerFooterDate=Date/Time
|
||||
headerFooterPage=Page #
|
||||
headerFooterPageTotal=Page # of #
|
||||
headerFooterCustom=Custom...
|
||||
customHeaderFooterPrompt=Please enter your custom header/footer text
|
|
@ -40,6 +40,7 @@
|
|||
+ locale/@AB_CD@/global/printPageSetup.dtd (%chrome/global/printPageSetup.dtd)
|
||||
+ locale/@AB_CD@/global/printPreview.dtd (%chrome/global/printPreview.dtd)
|
||||
+ locale/@AB_CD@/global/printPreviewProgress.dtd (%chrome/global/printPreviewProgress.dtd)
|
||||
locale/@AB_CD@/global/gnomeprintdialog.properties (%chrome/global/gnomeprintdialog.properties)
|
||||
+ locale/@AB_CD@/global/printProgress.dtd (%chrome/global/printProgress.dtd)
|
||||
+ locale/@AB_CD@/global/regionNames.properties (%chrome/global/regionNames.properties)
|
||||
+ locale/@AB_CD@/global/dialog.properties (%chrome/global/dialog.properties)
|
||||
|
|
|
@ -77,8 +77,12 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
|
|||
EXPORTS += nsIDragSessionBeOS.h
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
|
||||
EXPORTS += nsIDragSessionGTK.h
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
EXPORTS += \
|
||||
nsIDragSessionGTK.h \
|
||||
nsIPrintDialogService.h \
|
||||
$(NULL)
|
||||
|
||||
endif
|
||||
|
||||
XPIDLSRCS = \
|
||||
|
@ -118,6 +122,10 @@ XPIDLSRCS += nsIPrintSettingsX.idl \
|
|||
nsIPrintSessionX.idl
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
XPIDLSRCS += nsIPrintSettingsGTK.idl
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
XPIDLSRCS += nsIRwsService.idl
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kenneth Herron <kherron@fmailbox.com>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIPrintDialogService_h__
|
||||
#define nsIPrintDialogService_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIPrintSettings;
|
||||
|
||||
/*
|
||||
* Interface to a print dialog accessed through the widget library.
|
||||
*/
|
||||
|
||||
#define NS_IPRINTDIALOGSERVICE_IID \
|
||||
{ 0x3715eb1a, 0xb314, 0x447c, \
|
||||
{ 0x95, 0x33, 0xd0, 0x6a, 0x6d, 0xa6, 0xa6, 0xf0 } }
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class nsIPrintDialogService : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRINTDIALOGSERVICE_IID)
|
||||
|
||||
/**
|
||||
* Initialize the service.
|
||||
* @return NS_OK or a suitable error.
|
||||
*/
|
||||
NS_IMETHOD Init() = 0;
|
||||
|
||||
/**
|
||||
* Show the print dialog.
|
||||
* @param aSettings On entry, this contains initial settings for the
|
||||
* print dialog. On return, if the print operation should
|
||||
* proceed then this contains settings for the print
|
||||
* operation.
|
||||
* @return NS_OK if the print operation should proceed
|
||||
* @return NS_ERROR_ABORT if the user indicated not to proceed
|
||||
* @return a suitable error for failures to show the print dialog.
|
||||
*/
|
||||
NS_IMETHOD Show(nsIPrintSettings *aSettings) = 0;
|
||||
|
||||
/**
|
||||
* Show the page setup dialog. Note that there is no way to tell whether the user clicked OK or Cancel on the
|
||||
* dialog.
|
||||
* @param aSettings On entry, this contains initial settings for the
|
||||
* page setup dialog. On return, this contains new default page setup options.
|
||||
* @return NS_OK if everything is OK.
|
||||
* @return a suitable error for failures to show the page setup dialog.
|
||||
*/
|
||||
NS_IMETHOD ShowPageSetup(nsIPrintSettings *aSettings) = 0;
|
||||
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIPrintDialogService, NS_IPRINTDIALOGSERVICE_IID)
|
||||
|
||||
#define NS_PRINTDIALOGSERVICE_CONTRACTID ("@mozilla.org/widget/printdialog-service;1")
|
||||
|
||||
#endif // nsIPrintDialogService_h__
|
||||
|
|
@ -167,3 +167,6 @@
|
|||
{ 0x2f977d53, 0x5485, 0x11d4, \
|
||||
{ 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } }
|
||||
|
||||
#define NS_PRINTDIALOGSERVICE_CID \
|
||||
{ 0x06beec76, 0xa183, 0x4d9f, \
|
||||
{ 0x85, 0xdd, 0x08, 0x5f, 0x26, 0xda, 0x56, 0x5a } }
|
||||
|
|
|
@ -108,9 +108,9 @@ CPPSRCS = \
|
|||
nsPrintOptionsGTK.cpp \
|
||||
nsImageToPixbuf.cpp \
|
||||
nsAccessibilityHelper.cpp \
|
||||
nsPrintJobFactoryGTK.cpp \
|
||||
nsPrintJobGTK.cpp \
|
||||
nsIdleServiceGTK.cpp \
|
||||
nsPrintDialogGTK.cpp \
|
||||
nsPrintSettingsGTK.cpp \
|
||||
$(NULL)
|
||||
|
||||
# build our subdirs, too
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
|
||||
* Ken Herron <kherron+mozilla@fmailbox.com>
|
||||
* Julien Lafon <julien.lafon@gmail.com>
|
||||
* Michael Ventnor <m.ventnor@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
|
@ -66,12 +67,16 @@
|
|||
#include "nsPaperPS.h" /* Paper size list */
|
||||
#endif /* USE_POSTSCRIPT */
|
||||
|
||||
#include "nsPrintJobFactoryGTK.h"
|
||||
#include "nsIPrintJobGTK.h"
|
||||
#include "nsIPrintSettingsGTK.h"
|
||||
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
|
||||
#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
|
||||
|
||||
|
@ -382,13 +387,11 @@ nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull;
|
|||
nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()
|
||||
{
|
||||
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()\n"));
|
||||
mPrintJob = nsnull;
|
||||
}
|
||||
|
||||
nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()
|
||||
{
|
||||
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()\n"));
|
||||
delete mPrintJob;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
|
||||
|
@ -410,18 +413,30 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac
|
|||
height /= 20;
|
||||
|
||||
DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", path, width, height));
|
||||
nsresult rv;
|
||||
|
||||
nsresult rv = nsPrintJobFactoryGTK::CreatePrintJob(this, mPrintJob);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
// Spool file. Use Glib's temporary file function since we're
|
||||
// already dependent on the gtk software stack.
|
||||
gchar *buf;
|
||||
gint fd = g_file_open_tmp("XXXXXX.tmp", &buf, nsnull);
|
||||
if (-1 == fd)
|
||||
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
||||
close(fd);
|
||||
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
rv = mPrintJob->GetSpoolFile(getter_AddRefs(file));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(buf), PR_FALSE,
|
||||
getter_AddRefs(mSpoolFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
unlink(buf);
|
||||
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
||||
}
|
||||
|
||||
mSpoolName = buf;
|
||||
g_free(buf);
|
||||
|
||||
mSpoolFile->SetPermissions(0600);
|
||||
|
||||
nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
|
||||
rv = stream->Init(file, -1, -1, 0);
|
||||
rv = stream->Init(mSpoolFile, -1, -1, 0);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -429,10 +444,31 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac
|
|||
mPrintSettings->GetOutputFormat(&format);
|
||||
|
||||
nsRefPtr<gfxASurface> surface;
|
||||
if (nsIPrintSettings::kOutputFormatPDF == format) {
|
||||
surface = new gfxPDFSurface(stream, gfxSize(width, height));
|
||||
gfxSize surfaceSize(width, height);
|
||||
|
||||
// Determine the real format with some GTK magic
|
||||
if (format == nsIPrintSettings::kOutputFormatNative) {
|
||||
nsCOMPtr<nsIPrintSettingsGTK> printSettingsGTK(do_QueryInterface(mPrintSettings));
|
||||
GtkPrintSettings* theSettings;
|
||||
printSettingsGTK->GetGtkPrintSettings(&theSettings);
|
||||
const gchar* fmtGTK = gtk_print_settings_get(theSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
|
||||
if (!fmtGTK) {
|
||||
// Likely not print-to-file, check printer's capabilities
|
||||
GtkPrinter* thePrinter;
|
||||
printSettingsGTK->GetGtkPrinter(&thePrinter);
|
||||
format = (gtk_printer_accepts_pdf(thePrinter)) ? nsIPrintSettings::kOutputFormatPDF
|
||||
: nsIPrintSettings::kOutputFormatPS;
|
||||
} else if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) {
|
||||
format = nsIPrintSettings::kOutputFormatPDF;
|
||||
} else {
|
||||
format = nsIPrintSettings::kOutputFormatPS;
|
||||
}
|
||||
}
|
||||
|
||||
if (format == nsIPrintSettings::kOutputFormatPDF) {
|
||||
surface = new gfxPDFSurface(stream, surfaceSize);
|
||||
} else {
|
||||
surface = new gfxPSSurface(stream, gfxSize(width, height));
|
||||
surface = new gfxPSSurface(stream, surfaceSize);
|
||||
}
|
||||
|
||||
if (!surface)
|
||||
|
@ -453,104 +489,28 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIWidget *aWidget,
|
|||
PRBool aIsPrintPreview)
|
||||
{
|
||||
DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p)\n", aPS));
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (gtk_major_version < 2 ||
|
||||
(gtk_major_version == 2 && gtk_minor_version < 10))
|
||||
return NS_ERROR_NOT_AVAILABLE; // I'm so sorry bz
|
||||
|
||||
mPrintSettings = aPS;
|
||||
mIsPPreview = aIsPrintPreview;
|
||||
|
||||
// if there is a current selection then enable the "Selection" radio button
|
||||
rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
// This is only set by embedders
|
||||
PRBool toFile;
|
||||
aPS->GetPrintToFile(&toFile);
|
||||
mToPrinter = !toFile;
|
||||
|
||||
GlobalPrinters::GetInstance()->FreeGlobalPrinters();
|
||||
nsCOMPtr<nsIPrintSettingsGTK> printSettingsGTK(do_QueryInterface(aPS));
|
||||
if (!printSettingsGTK)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (aPS) {
|
||||
PRBool reversed = PR_FALSE;
|
||||
PRBool color = PR_FALSE;
|
||||
PRBool tofile = PR_FALSE;
|
||||
PRInt16 printRange = nsIPrintSettings::kRangeAllPages;
|
||||
PRInt32 orientation = NS_PORTRAIT;
|
||||
PRInt32 fromPage = 1;
|
||||
PRInt32 toPage = 1;
|
||||
PRUnichar *command = nsnull;
|
||||
PRInt32 copies = 1;
|
||||
PRUnichar *printer = nsnull;
|
||||
PRUnichar *papername = nsnull;
|
||||
PRUnichar *plexname = nsnull;
|
||||
PRUnichar *resolutionname = nsnull;
|
||||
PRUnichar *colorspace = nsnull;
|
||||
PRBool downloadfonts = PR_TRUE;
|
||||
PRUnichar *printfile = nsnull;
|
||||
double dleft = 0.5;
|
||||
double dright = 0.5;
|
||||
double dtop = 0.5;
|
||||
double dbottom = 0.5;
|
||||
printSettingsGTK->GetGtkPrinter(&mGtkPrinter);
|
||||
printSettingsGTK->GetGtkPrintSettings(&mGtkPrintSettings);
|
||||
printSettingsGTK->GetGtkPageSetup(&mGtkPageSetup);
|
||||
|
||||
aPS->GetPrinterName(&printer);
|
||||
aPS->GetPrintReversed(&reversed);
|
||||
aPS->GetPrintInColor(&color);
|
||||
aPS->GetPaperName(&papername);
|
||||
aPS->GetResolutionName(&resolutionname);
|
||||
aPS->GetColorspace(&colorspace);
|
||||
aPS->GetDownloadFonts(&downloadfonts);
|
||||
aPS->GetPlexName(&plexname);
|
||||
aPS->GetOrientation(&orientation);
|
||||
aPS->GetPrintCommand(&command);
|
||||
aPS->GetPrintRange(&printRange);
|
||||
aPS->GetToFileName(&printfile);
|
||||
aPS->GetPrintToFile(&tofile);
|
||||
aPS->GetStartPageRange(&fromPage);
|
||||
aPS->GetEndPageRange(&toPage);
|
||||
aPS->GetNumCopies(&copies);
|
||||
aPS->GetMarginTop(&dtop);
|
||||
aPS->GetMarginLeft(&dleft);
|
||||
aPS->GetMarginBottom(&dbottom);
|
||||
aPS->GetMarginRight(&dright);
|
||||
|
||||
if (printfile)
|
||||
PL_strncpyz(mPath, NS_ConvertUTF16toUTF8(printfile).get(), sizeof(mPath));
|
||||
if (command)
|
||||
PL_strncpyz(mCommand, NS_ConvertUTF16toUTF8(command).get(), sizeof(mCommand));
|
||||
if (printer)
|
||||
PL_strncpyz(mPrinter, NS_ConvertUTF16toUTF8(printer).get(), sizeof(mPrinter));
|
||||
if (papername)
|
||||
PL_strncpyz(mPaperName, NS_ConvertUTF16toUTF8(papername).get(), sizeof(mPaperName));
|
||||
if (plexname)
|
||||
PL_strncpyz(mPlexName, NS_ConvertUTF16toUTF8(plexname).get(), sizeof(mPlexName));
|
||||
if (resolutionname)
|
||||
PL_strncpyz(mResolutionName, NS_ConvertUTF16toUTF8(resolutionname).get(), sizeof(mResolutionName));
|
||||
if (colorspace)
|
||||
PL_strncpyz(mColorspace, NS_ConvertUTF16toUTF8(colorspace).get(), sizeof(mColorspace));
|
||||
|
||||
DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
|
||||
DO_PR_DEBUG_LOG(("printRange %d\n", printRange));
|
||||
DO_PR_DEBUG_LOG(("fromPage %d\n", fromPage));
|
||||
DO_PR_DEBUG_LOG(("toPage %d\n", toPage));
|
||||
DO_PR_DEBUG_LOG(("tofile %d\n", tofile));
|
||||
DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUTF16toUTF8(printfile).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUTF16toUTF8(command).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUTF16toUTF8(printer).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUTF16toUTF8(papername).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("plexname '%s'\n", plexname? NS_ConvertUTF16toUTF8(plexname).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("resolution '%s'\n", resolutionname? NS_ConvertUTF16toUTF8(resolutionname).get():"<NULL>"));
|
||||
DO_PR_DEBUG_LOG(("colorspace '%s'\n", colorspace? NS_ConvertUTF16toUTF8(colorspace).get():"<NULL>"));
|
||||
|
||||
mTop = dtop;
|
||||
mBottom = dbottom;
|
||||
mLeft = dleft;
|
||||
mRight = dright;
|
||||
mFpf = !reversed;
|
||||
mDownloadFonts = downloadfonts;
|
||||
mGrayscale = !color;
|
||||
mOrientation = orientation;
|
||||
mToPrinter = !tofile;
|
||||
mCopies = copies;
|
||||
mIsPPreview = aIsPrintPreview;
|
||||
mCancel = PR_FALSE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::GetToPrinter(PRBool &aToPrinter)
|
||||
|
@ -688,14 +648,64 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::ClosePrintManager()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
|
||||
static void
|
||||
print_callback(GtkPrintJob *aJob, gpointer aData, GError *aError) {
|
||||
g_object_unref(aJob);
|
||||
((nsILocalFile*) aData)->Remove(PR_FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
ns_release_macro(gpointer aData) {
|
||||
nsILocalFile* spoolFile = (nsILocalFile*) aData;
|
||||
NS_RELEASE(spoolFile);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName,
|
||||
PRInt32 aStartPage, PRInt32 aEndPage)
|
||||
{
|
||||
if (mToPrinter)
|
||||
mPrintJob = gtk_print_job_new(NS_ConvertUTF16toUTF8(aTitle).get(), mGtkPrinter,
|
||||
mGtkPrintSettings, mGtkPageSetup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument()
|
||||
{
|
||||
return mPrintJob->Submit();
|
||||
if (mToPrinter) {
|
||||
if (!gtk_print_job_set_source_file(mPrintJob, mSpoolName.get(), NULL))
|
||||
return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
|
||||
|
||||
NS_ADDREF(mSpoolFile);
|
||||
gtk_print_job_send(mPrintJob, print_callback, mSpoolFile, ns_release_macro);
|
||||
} else {
|
||||
// Handle print-to-file ourselves for the benefit of embedders
|
||||
nsXPIDLString targetPath;
|
||||
nsCOMPtr<nsILocalFile> destFile;
|
||||
mPrintSettings->GetToFileName(getter_Copies(targetPath));
|
||||
|
||||
nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath),
|
||||
PR_FALSE, getter_AddRefs(destFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString destLeafName;
|
||||
rv = destFile->GetLeafName(destLeafName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> destDir;
|
||||
rv = destFile->GetParent(getter_AddRefs(destDir));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mSpoolFile->MoveTo(destDir, destLeafName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// This is the standard way to get the UNIX umask. Ugh.
|
||||
mode_t mask = umask(0);
|
||||
umask(mask);
|
||||
// If you're not familiar with umasks, they contain the bits of what NOT to set in the permissions
|
||||
// (thats because files and directories have different numbers of bits for their permissions)
|
||||
destFile->SetPermissions(0666 & ~(mask));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* Get prefs for printer
|
||||
|
|
|
@ -43,9 +43,14 @@
|
|||
#include "nsIPrintSettings.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsCRT.h" /* should be <limits.h>? */
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkprinter.h>
|
||||
#include <gtk/gtkprintjob.h>
|
||||
|
||||
class nsIPrintJobGTK;
|
||||
|
||||
#define NS_PORTRAIT 0
|
||||
|
@ -117,7 +122,15 @@ protected:
|
|||
float mRight; /* right margin */
|
||||
float mTop; /* top margin */
|
||||
float mBottom; /* bottom margin */
|
||||
nsIPrintJobGTK * mPrintJob;
|
||||
|
||||
GtkPrintJob* mPrintJob;
|
||||
GtkPrinter* mGtkPrinter;
|
||||
GtkPrintSettings* mGtkPrintSettings;
|
||||
GtkPageSetup* mGtkPageSetup;
|
||||
|
||||
nsCString mSpoolName;
|
||||
nsCOMPtr<nsILocalFile> mSpoolFile;
|
||||
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GTK2 print dialog interface.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kenneth Herron <kherron@fmailbox.com>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsPrintDialog_h__
|
||||
#define nsPrintDialog_h__
|
||||
|
||||
#include "nsIPrintDialogService.h"
|
||||
|
||||
class nsIPrintSettings;
|
||||
|
||||
class nsPrintDialogServiceGTK : public nsIPrintDialogService
|
||||
{
|
||||
public:
|
||||
nsPrintDialogServiceGTK();
|
||||
virtual ~nsPrintDialogServiceGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHODIMP Init();
|
||||
NS_IMETHODIMP Show(nsIPrintSettings *aSettings);
|
||||
NS_IMETHODIMP ShowPageSetup(nsIPrintSettings *aSettings);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -35,7 +35,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsPrintOptionsGTK.h"
|
||||
|
||||
#include "nsPrintSettingsGTK.h"
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
@ -55,3 +55,16 @@ nsPrintOptionsGTK::~nsPrintOptionsGTK()
|
|||
{
|
||||
}
|
||||
|
||||
/* nsIPrintSettings CreatePrintSettings (); */
|
||||
nsresult nsPrintOptionsGTK::_CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
nsPrintSettingsGTK* printSettings = new nsPrintSettingsGTK(); // does not initially ref count
|
||||
NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*_retval = printSettings); // ref count
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
nsPrintOptionsGTK();
|
||||
virtual ~nsPrintOptionsGTK();
|
||||
|
||||
virtual nsresult _CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "nsIPrefBranch.h"
|
||||
#include "nsImageToPixbuf.h"
|
||||
#include "nsIdleServiceGTK.h"
|
||||
#include "nsPrintDialogGTK.h"
|
||||
|
||||
#ifdef NATIVE_THEME_SUPPORT
|
||||
#include "nsNativeThemeGTK.h"
|
||||
|
@ -97,6 +98,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceGTK)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceGTK, Init)
|
||||
|
||||
static NS_IMETHODIMP
|
||||
nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
|
@ -274,6 +276,10 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_IDLE_SERVICE_CID,
|
||||
"@mozilla.org/widget/idleservice;1",
|
||||
nsIdleServiceGTKConstructor },
|
||||
{ "Native Print Dialog",
|
||||
NS_PRINTDIALOGSERVICE_CID,
|
||||
NS_PRINTDIALOGSERVICE_CONTRACTID,
|
||||
nsPrintDialogServiceGTKConstructor },
|
||||
};
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
|
|
Загрузка…
Ссылка в новой задаче