2008-01-21 03:47:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
#include "nsPrintSettingsGTK.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2008-01-21 03:47:25 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include <stdlib.h>
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
gboolean ref_printer(GtkPrinter *aPrinter, gpointer aData)
|
|
|
|
{
|
|
|
|
((nsPrintSettingsGTK*) aData)->SetGtkPrinter(aPrinter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
gboolean printer_enumerator(GtkPrinter *aPrinter, gpointer aData)
|
|
|
|
{
|
|
|
|
if (gtk_printer_is_default(aPrinter))
|
|
|
|
return ref_printer(aPrinter, aData);
|
|
|
|
|
|
|
|
return FALSE; // Keep 'em coming...
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
GtkPaperSize* moz_gtk_paper_size_copy_to_new_custom(GtkPaperSize* oldPaperSize)
|
|
|
|
{
|
|
|
|
// We make a "custom-ified" copy of the paper size so it can be changed later.
|
|
|
|
return gtk_paper_size_new_custom(gtk_paper_size_get_name(oldPaperSize),
|
|
|
|
gtk_paper_size_get_display_name(oldPaperSize),
|
|
|
|
gtk_paper_size_get_width(oldPaperSize, GTK_UNIT_INCH),
|
|
|
|
gtk_paper_size_get_height(oldPaperSize, GTK_UNIT_INCH),
|
|
|
|
GTK_UNIT_INCH);
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsGTK,
|
|
|
|
nsPrintSettings,
|
|
|
|
nsPrintSettingsGTK)
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
nsPrintSettingsGTK::nsPrintSettingsGTK() :
|
2013-10-08 18:47:37 +00:00
|
|
|
mPageSetup(nullptr),
|
|
|
|
mPrintSettings(nullptr),
|
|
|
|
mGTKPrinter(nullptr),
|
2011-10-03 07:56:21 +00:00
|
|
|
mPrintSelectionOnly(false)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
// The aim here is to set up the objects enough that silent printing works well.
|
|
|
|
// These will be replaced anyway if the print dialog is used.
|
|
|
|
mPrintSettings = gtk_print_settings_new();
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPageSetup* pageSetup = gtk_page_setup_new();
|
|
|
|
SetGtkPageSetup(pageSetup);
|
|
|
|
g_object_unref(pageSetup);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
SetOutputFormat(nsIPrintSettings::kOutputFormatNative);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
nsPrintSettingsGTK::~nsPrintSettingsGTK()
|
|
|
|
{
|
|
|
|
if (mPageSetup) {
|
|
|
|
g_object_unref(mPageSetup);
|
2013-10-08 18:47:37 +00:00
|
|
|
mPageSetup = nullptr;
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
if (mPrintSettings) {
|
|
|
|
g_object_unref(mPrintSettings);
|
2013-10-08 18:47:37 +00:00
|
|
|
mPrintSettings = nullptr;
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
if (mGTKPrinter) {
|
|
|
|
g_object_unref(mGTKPrinter);
|
2013-10-08 18:47:37 +00:00
|
|
|
mGTKPrinter = nullptr;
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
nsPrintSettingsGTK::nsPrintSettingsGTK(const nsPrintSettingsGTK& aPS) :
|
2013-10-08 18:47:37 +00:00
|
|
|
mPageSetup(nullptr),
|
|
|
|
mPrintSettings(nullptr),
|
|
|
|
mGTKPrinter(nullptr),
|
2011-10-03 07:56:21 +00:00
|
|
|
mPrintSelectionOnly(false)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
*this = aPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
nsPrintSettingsGTK& nsPrintSettingsGTK::operator=(const nsPrintSettingsGTK& rhs)
|
|
|
|
{
|
|
|
|
if (this == &rhs) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintSettings::operator=(rhs);
|
|
|
|
|
|
|
|
if (mPageSetup)
|
|
|
|
g_object_unref(mPageSetup);
|
|
|
|
mPageSetup = gtk_page_setup_copy(rhs.mPageSetup);
|
2008-03-19 20:51:42 +00:00
|
|
|
// NOTE: No need to re-initialize mUnwriteableMargin here (even
|
|
|
|
// though mPageSetup is changing). It'll be copied correctly by
|
|
|
|
// nsPrintSettings::operator=.
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
if (mPrintSettings)
|
|
|
|
g_object_unref(mPrintSettings);
|
|
|
|
mPrintSettings = gtk_print_settings_copy(rhs.mPrintSettings);
|
|
|
|
|
|
|
|
if (mGTKPrinter)
|
|
|
|
g_object_unref(mGTKPrinter);
|
|
|
|
mGTKPrinter = (GtkPrinter*) g_object_ref(rhs.mGTKPrinter);
|
|
|
|
|
|
|
|
mPrintSelectionOnly = rhs.mPrintSelectionOnly;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** -------------------------------------------
|
|
|
|
*/
|
|
|
|
nsresult nsPrintSettingsGTK::_Clone(nsIPrintSettings **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
nsPrintSettingsGTK *newSettings = new nsPrintSettingsGTK(*this);
|
|
|
|
if (!newSettings)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*_retval = newSettings;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** -------------------------------------------
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::_Assign(nsIPrintSettings *aPS)
|
|
|
|
{
|
|
|
|
nsPrintSettingsGTK *printSettingsGTK = static_cast<nsPrintSettingsGTK*>(aPS);
|
|
|
|
if (!printSettingsGTK)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
*this = *printSettingsGTK;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsPrintSettingsGTK::SetGtkPageSetup(GtkPageSetup *aPageSetup)
|
|
|
|
{
|
|
|
|
if (mPageSetup)
|
|
|
|
g_object_unref(mPageSetup);
|
|
|
|
|
|
|
|
mPageSetup = (GtkPageSetup*) g_object_ref(aPageSetup);
|
2008-03-19 20:51:42 +00:00
|
|
|
InitUnwriteableMargin();
|
2008-01-21 03:47:25 +00:00
|
|
|
|
2015-11-24 22:07:21 +00:00
|
|
|
// If the paper size is not custom, then we make a custom copy of the
|
|
|
|
// GtkPaperSize, so it can be mutable. If a GtkPaperSize wasn't made as
|
|
|
|
// custom, its properties are immutable.
|
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(aPageSetup);
|
|
|
|
if (!gtk_paper_size_is_custom(paperSize)) {
|
|
|
|
GtkPaperSize* customPaperSize =
|
|
|
|
moz_gtk_paper_size_copy_to_new_custom(paperSize);
|
|
|
|
gtk_page_setup_set_paper_size(mPageSetup, customPaperSize);
|
|
|
|
gtk_paper_size_free(customPaperSize);
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
SaveNewPageSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsPrintSettingsGTK::SetGtkPrintSettings(GtkPrintSettings *aPrintSettings)
|
|
|
|
{
|
|
|
|
if (mPrintSettings)
|
|
|
|
g_object_unref(mPrintSettings);
|
|
|
|
|
|
|
|
mPrintSettings = (GtkPrintSettings*) g_object_ref(aPrintSettings);
|
|
|
|
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_print_settings_get_paper_size(aPrintSettings);
|
|
|
|
if (paperSize) {
|
|
|
|
GtkPaperSize* customPaperSize =
|
|
|
|
moz_gtk_paper_size_copy_to_new_custom(paperSize);
|
|
|
|
gtk_paper_size_free(paperSize);
|
|
|
|
gtk_page_setup_set_paper_size(mPageSetup, customPaperSize);
|
|
|
|
gtk_paper_size_free(customPaperSize);
|
|
|
|
} else {
|
|
|
|
// paperSize was null, and so we add the paper size in the GtkPageSetup to
|
|
|
|
// the settings.
|
|
|
|
SaveNewPageSize();
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsPrintSettingsGTK::SetGtkPrinter(GtkPrinter *aPrinter)
|
|
|
|
{
|
|
|
|
if (mGTKPrinter)
|
|
|
|
g_object_unref(mGTKPrinter);
|
2015-03-05 21:05:33 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
mGTKPrinter = (GtkPrinter*) g_object_ref(aPrinter);
|
2015-07-31 17:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPrintSettingsGTK::GetOutputFormat(int16_t *aOutputFormat)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOutputFormat);
|
|
|
|
|
|
|
|
int16_t format;
|
|
|
|
nsresult rv = nsPrintSettings::GetOutputFormat(&format);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == nsIPrintSettings::kOutputFormatNative) {
|
|
|
|
const gchar* fmtGTK =
|
|
|
|
gtk_print_settings_get(mPrintSettings,
|
|
|
|
GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
|
|
|
|
if (fmtGTK) {
|
|
|
|
if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) {
|
|
|
|
format = nsIPrintSettings::kOutputFormatPDF;
|
|
|
|
} else {
|
|
|
|
format = nsIPrintSettings::kOutputFormatPS;
|
|
|
|
}
|
|
|
|
} else if (GTK_IS_PRINTER(mGTKPrinter)) {
|
|
|
|
// Prior to gtk 2.24, gtk_printer_accepts_pdf() and
|
|
|
|
// gtk_printer_accepts_ps() always returned true regardless of the
|
|
|
|
// printer's capability.
|
|
|
|
bool shouldTrustGTK =
|
|
|
|
(gtk_major_version > 2 ||
|
|
|
|
(gtk_major_version == 2 && gtk_minor_version >= 24));
|
|
|
|
bool acceptsPDF = shouldTrustGTK && gtk_printer_accepts_pdf(mGTKPrinter);
|
2015-03-05 21:05:33 +00:00
|
|
|
|
2015-07-31 17:53:49 +00:00
|
|
|
format = acceptsPDF ? nsIPrintSettings::kOutputFormatPDF
|
|
|
|
: nsIPrintSettings::kOutputFormatPS;
|
|
|
|
}
|
|
|
|
}
|
2015-03-05 21:05:33 +00:00
|
|
|
|
2015-07-31 17:53:49 +00:00
|
|
|
*aOutputFormat = format;
|
|
|
|
return NS_OK;
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplementation of nsPrintSettings functions so that we get the values
|
|
|
|
* from the GTK objects rather than our own variables.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsPrintSettingsGTK::GetPrintRange(int16_t *aPrintRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrintRange);
|
|
|
|
if (mPrintSelectionOnly) {
|
|
|
|
*aPrintRange = kRangeSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkPrintPages gtkRange = gtk_print_settings_get_print_pages(mPrintSettings);
|
|
|
|
if (gtkRange == GTK_PRINT_PAGES_RANGES)
|
|
|
|
*aPrintRange = kRangeSpecifiedPageRange;
|
|
|
|
else
|
|
|
|
*aPrintRange = kRangeAllPages;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsPrintSettingsGTK::SetPrintRange(int16_t aPrintRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
if (aPrintRange == kRangeSelection) {
|
2011-10-03 07:56:21 +00:00
|
|
|
mPrintSelectionOnly = true;
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-03 07:56:21 +00:00
|
|
|
mPrintSelectionOnly = false;
|
2008-01-21 03:47:25 +00:00
|
|
|
if (aPrintRange == kRangeSpecifiedPageRange)
|
|
|
|
gtk_print_settings_set_print_pages(mPrintSettings, GTK_PRINT_PAGES_RANGES);
|
|
|
|
else
|
|
|
|
gtk_print_settings_set_print_pages(mPrintSettings, GTK_PRINT_PAGES_ALL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetStartPageRange(int32_t *aStartPageRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
gint ctRanges;
|
|
|
|
GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
|
|
|
|
|
|
|
|
// Make sure we got a range.
|
|
|
|
if (ctRanges < 1) {
|
|
|
|
*aStartPageRange = 1;
|
|
|
|
} else {
|
|
|
|
// GTK supports multiple page ranges; gecko only supports 1. So find
|
|
|
|
// the lowest start page.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t start(lstRanges[0].start);
|
2008-01-21 03:47:25 +00:00
|
|
|
for (gint ii = 1; ii < ctRanges; ii++) {
|
2013-01-15 12:22:03 +00:00
|
|
|
start = std::min(lstRanges[ii].start, start);
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
*aStartPageRange = start + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(lstRanges);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::SetStartPageRange(int32_t aStartPageRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t endRange;
|
2008-01-21 03:47:25 +00:00
|
|
|
GetEndPageRange(&endRange);
|
|
|
|
|
|
|
|
GtkPageRange gtkRange;
|
|
|
|
gtkRange.start = aStartPageRange - 1;
|
|
|
|
gtkRange.end = endRange - 1;
|
|
|
|
|
|
|
|
gtk_print_settings_set_page_ranges(mPrintSettings, >kRange, 1);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetEndPageRange(int32_t *aEndPageRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
gint ctRanges;
|
|
|
|
GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
|
|
|
|
|
|
|
|
if (ctRanges < 1) {
|
|
|
|
*aEndPageRange = 1;
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t end(lstRanges[0].end);
|
2008-01-21 03:47:25 +00:00
|
|
|
for (gint ii = 1; ii < ctRanges; ii++) {
|
2013-01-15 12:22:03 +00:00
|
|
|
end = std::max(lstRanges[ii].end, end);
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
*aEndPageRange = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(lstRanges);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::SetEndPageRange(int32_t aEndPageRange)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t startRange;
|
2008-01-21 03:47:25 +00:00
|
|
|
GetStartPageRange(&startRange);
|
|
|
|
|
|
|
|
GtkPageRange gtkRange;
|
|
|
|
gtkRange.start = startRange - 1;
|
|
|
|
gtkRange.end = aEndPageRange - 1;
|
|
|
|
|
|
|
|
gtk_print_settings_set_page_ranges(mPrintSettings, >kRange, 1);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPrintSettingsGTK::GetPrintReversed(bool *aPrintReversed)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
*aPrintReversed = gtk_print_settings_get_reverse(mPrintSettings);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPrintSettingsGTK::SetPrintReversed(bool aPrintReversed)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
gtk_print_settings_set_reverse(mPrintSettings, aPrintReversed);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPrintSettingsGTK::GetPrintInColor(bool *aPrintInColor)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
*aPrintInColor = gtk_print_settings_get_use_color(mPrintSettings);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsPrintSettingsGTK::SetPrintInColor(bool aPrintInColor)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
gtk_print_settings_set_use_color(mPrintSettings, aPrintInColor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetOrientation(int32_t *aOrientation)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOrientation);
|
|
|
|
|
|
|
|
GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup);
|
|
|
|
switch (gtkOrient) {
|
|
|
|
case GTK_PAGE_ORIENTATION_LANDSCAPE:
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
|
|
|
|
*aOrientation = kLandscapeOrientation;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_PAGE_ORIENTATION_PORTRAIT:
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
|
|
|
|
default:
|
|
|
|
*aOrientation = kPortraitOrientation;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::SetOrientation(int32_t aOrientation)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
GtkPageOrientation gtkOrient;
|
|
|
|
if (aOrientation == kLandscapeOrientation)
|
|
|
|
gtkOrient = GTK_PAGE_ORIENTATION_LANDSCAPE;
|
|
|
|
else
|
|
|
|
gtkOrient = GTK_PAGE_ORIENTATION_PORTRAIT;
|
|
|
|
|
|
|
|
gtk_print_settings_set_orientation(mPrintSettings, gtkOrient);
|
|
|
|
gtk_page_setup_set_orientation(mPageSetup, gtkOrient);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::GetToFileName(char16_t * *aToFileName)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
// Get the gtk output filename
|
|
|
|
const char* gtk_output_uri = gtk_print_settings_get(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI);
|
|
|
|
if (!gtk_output_uri) {
|
|
|
|
*aToFileName = ToNewUnicode(mToFileName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert to an nsIFile
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2008-04-25 10:48:57 +00:00
|
|
|
nsresult rv = NS_GetFileFromURLSpec(nsDependentCString(gtk_output_uri),
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
// Extract the path
|
|
|
|
nsAutoString path;
|
2008-04-25 10:48:57 +00:00
|
|
|
rv = file->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
*aToFileName = ToNewUnicode(path);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-04-25 10:48:57 +00:00
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::SetToFileName(const char16_t * aToFileName)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
if (aToFileName[0] == 0) {
|
|
|
|
mToFileName.SetLength(0);
|
2013-10-08 18:47:37 +00:00
|
|
|
gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI,
|
|
|
|
nullptr);
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-10 06:07:34 +00:00
|
|
|
if (StringEndsWith(nsDependentString(aToFileName), NS_LITERAL_STRING(".ps"))) {
|
|
|
|
gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "ps");
|
|
|
|
} else {
|
|
|
|
gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
|
|
|
|
}
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2011-10-03 07:56:21 +00:00
|
|
|
nsresult rv = NS_NewLocalFile(nsDependentString(aToFileName), true,
|
2008-04-25 10:48:57 +00:00
|
|
|
getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
// Convert the nsIFile to a URL
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString url;
|
2008-04-25 10:48:57 +00:00
|
|
|
rv = NS_GetURLSpecFromFile(file, url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, url.get());
|
|
|
|
mToFileName = aToFileName;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::GetPrinterName(char16_t * *aPrinter)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
const char* gtkPrintName = gtk_print_settings_get_printer(mPrintSettings);
|
|
|
|
if (!gtkPrintName) {
|
|
|
|
if (GTK_IS_PRINTER(mGTKPrinter)) {
|
|
|
|
gtkPrintName = gtk_printer_get_name(mGTKPrinter);
|
|
|
|
} else {
|
2008-01-22 00:09:37 +00:00
|
|
|
// This mimics what nsPrintSettingsImpl does when we try to Get before we Set
|
|
|
|
nsXPIDLString nullPrintName;
|
|
|
|
*aPrinter = ToNewUnicode(nullPrintName);
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 07:34:20 +00:00
|
|
|
*aPrinter = UTF8ToNewUnicode(nsDependentCString(gtkPrintName));
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::SetPrinterName(const char16_t * aPrinter)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 gtkPrinter(aPrinter);
|
|
|
|
|
|
|
|
if (StringBeginsWith(gtkPrinter, NS_LITERAL_CSTRING("CUPS/"))) {
|
|
|
|
// Strip off "CUPS/"; GTK might recognize the rest
|
|
|
|
gtkPrinter.Cut(0, strlen("CUPS/"));
|
|
|
|
}
|
|
|
|
|
2008-08-28 19:01:26 +00:00
|
|
|
// Give mPrintSettings the passed-in printer name if either...
|
|
|
|
// - it has no printer name stored yet
|
|
|
|
// - it has an existing printer name that's different from
|
|
|
|
// the name passed to this function.
|
|
|
|
const char* oldPrinterName = gtk_print_settings_get_printer(mPrintSettings);
|
|
|
|
if (!oldPrinterName || !gtkPrinter.Equals(oldPrinterName)) {
|
2011-10-03 07:56:21 +00:00
|
|
|
mIsInitedFromPrinter = false;
|
|
|
|
mIsInitedFromPrefs = false;
|
2008-01-21 03:47:25 +00:00
|
|
|
gtk_print_settings_set_printer(mPrintSettings, gtkPrinter.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetNumCopies(int32_t *aNumCopies)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumCopies);
|
|
|
|
*aNumCopies = gtk_print_settings_get_n_copies(mPrintSettings);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::SetNumCopies(int32_t aNumCopies)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
gtk_print_settings_set_n_copies(mPrintSettings, aNumCopies);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetScaling(double *aScaling)
|
|
|
|
{
|
|
|
|
*aScaling = gtk_print_settings_get_scale(mPrintSettings) / 100.0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetScaling(double aScaling)
|
|
|
|
{
|
|
|
|
gtk_print_settings_set_scale(mPrintSettings, aScaling * 100.0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::GetPaperName(char16_t * *aPaperName)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPaperName);
|
2015-11-24 22:07:21 +00:00
|
|
|
const gchar* name =
|
|
|
|
gtk_paper_size_get_name(gtk_page_setup_get_paper_size(mPageSetup));
|
|
|
|
*aPaperName = ToNewUnicode(NS_ConvertUTF8toUTF16(name));
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsPrintSettingsGTK::SetPaperName(const char16_t * aPaperName)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 gtkPaperName(aPaperName);
|
|
|
|
|
|
|
|
// Convert these Gecko names to GTK names
|
|
|
|
if (gtkPaperName.EqualsIgnoreCase("letter"))
|
|
|
|
gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LETTER);
|
|
|
|
else if (gtkPaperName.EqualsIgnoreCase("legal"))
|
|
|
|
gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LEGAL);
|
|
|
|
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* oldPaperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
gdouble width = gtk_paper_size_get_width(oldPaperSize, GTK_UNIT_INCH);
|
|
|
|
gdouble height = gtk_paper_size_get_height(oldPaperSize, GTK_UNIT_INCH);
|
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
// Try to get the display name from the name so our paper size fits in the Page Setup dialog.
|
|
|
|
GtkPaperSize* paperSize = gtk_paper_size_new(gtkPaperName.get());
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* customPaperSize =
|
|
|
|
gtk_paper_size_new_custom(gtkPaperName.get(),
|
|
|
|
gtk_paper_size_get_display_name(paperSize),
|
|
|
|
width, height, GTK_UNIT_INCH);
|
2008-01-21 03:47:25 +00:00
|
|
|
gtk_paper_size_free(paperSize);
|
|
|
|
|
2015-11-24 22:07:21 +00:00
|
|
|
gtk_page_setup_set_paper_size(mPageSetup, customPaperSize);
|
|
|
|
gtk_paper_size_free(customPaperSize);
|
2008-01-21 03:47:25 +00:00
|
|
|
SaveNewPageSize();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkUnit
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetGTKUnit(int16_t aGeckoUnit)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
if (aGeckoUnit == kPaperSizeMillimeters)
|
|
|
|
return GTK_UNIT_MM;
|
|
|
|
else
|
|
|
|
return GTK_UNIT_INCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPrintSettingsGTK::SaveNewPageSize()
|
|
|
|
{
|
2015-11-24 22:07:21 +00:00
|
|
|
gtk_print_settings_set_paper_size(mPrintSettings,
|
|
|
|
gtk_page_setup_get_paper_size(mPageSetup));
|
2008-01-21 03:47:25 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 20:51:42 +00:00
|
|
|
void
|
|
|
|
nsPrintSettingsGTK::InitUnwriteableMargin()
|
|
|
|
{
|
|
|
|
mUnwriteableMargin.SizeTo(
|
2010-08-13 09:59:16 +00:00
|
|
|
NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_top_margin(mPageSetup, GTK_UNIT_INCH)),
|
|
|
|
NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_right_margin(mPageSetup, GTK_UNIT_INCH)),
|
2013-03-06 08:05:55 +00:00
|
|
|
NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_bottom_margin(mPageSetup, GTK_UNIT_INCH)),
|
|
|
|
NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_left_margin(mPageSetup, GTK_UNIT_INCH))
|
2008-03-19 20:51:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE: Need a custom set of SetUnwriteableMargin functions, because
|
|
|
|
* whenever we change mUnwriteableMargin, we must pass the change
|
|
|
|
* down to our GTKPageSetup object. (This is needed in order for us
|
|
|
|
* to give the correct default values in nsPrintDialogGTK.)
|
|
|
|
*
|
|
|
|
* It's important that the following functions pass
|
|
|
|
* mUnwriteableMargin values rather than aUnwriteableMargin values
|
|
|
|
* to gtk_page_setup_set_[blank]_margin, because the two may not be
|
|
|
|
* the same. (Specifically, negative values of aUnwriteableMargin
|
|
|
|
* are ignored by the nsPrintSettings::SetUnwriteableMargin functions.)
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2009-01-15 03:27:09 +00:00
|
|
|
nsPrintSettingsGTK::SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin)
|
2008-03-19 20:51:42 +00:00
|
|
|
{
|
|
|
|
nsPrintSettings::SetUnwriteableMarginInTwips(aUnwriteableMargin);
|
|
|
|
gtk_page_setup_set_top_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.top), GTK_UNIT_INCH);
|
|
|
|
gtk_page_setup_set_left_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.left), GTK_UNIT_INCH);
|
|
|
|
gtk_page_setup_set_bottom_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom), GTK_UNIT_INCH);
|
|
|
|
gtk_page_setup_set_right_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.right), GTK_UNIT_INCH);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
|
|
|
|
{
|
|
|
|
nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop);
|
|
|
|
gtk_page_setup_set_top_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.top), GTK_UNIT_INCH);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
|
|
|
|
{
|
|
|
|
nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft);
|
|
|
|
gtk_page_setup_set_left_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.left), GTK_UNIT_INCH);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
|
|
|
|
{
|
|
|
|
nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom);
|
|
|
|
gtk_page_setup_set_bottom_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom), GTK_UNIT_INCH);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
|
|
|
|
{
|
|
|
|
nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight);
|
|
|
|
gtk_page_setup_set_right_margin(mPageSetup,
|
|
|
|
NS_TWIPS_TO_INCHES(mUnwriteableMargin.right), GTK_UNIT_INCH);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-21 03:47:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetPaperWidth(double *aPaperWidth)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPaperWidth);
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
*aPaperWidth =
|
|
|
|
gtk_paper_size_get_width(paperSize, GetGTKUnit(mPaperSizeUnit));
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetPaperWidth(double aPaperWidth)
|
|
|
|
{
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
gtk_paper_size_set_size(paperSize,
|
2008-01-21 03:47:25 +00:00
|
|
|
aPaperWidth,
|
2015-11-24 22:07:21 +00:00
|
|
|
gtk_paper_size_get_height(paperSize, GetGTKUnit(mPaperSizeUnit)),
|
2008-01-21 03:47:25 +00:00
|
|
|
GetGTKUnit(mPaperSizeUnit));
|
|
|
|
SaveNewPageSize();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetPaperHeight(double *aPaperHeight)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPaperHeight);
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
*aPaperHeight =
|
|
|
|
gtk_paper_size_get_height(paperSize, GetGTKUnit(mPaperSizeUnit));
|
2008-01-21 03:47:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetPaperHeight(double aPaperHeight)
|
|
|
|
{
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
gtk_paper_size_set_size(paperSize,
|
|
|
|
gtk_paper_size_get_width(paperSize, GetGTKUnit(mPaperSizeUnit)),
|
2008-01-21 03:47:25 +00:00
|
|
|
aPaperHeight,
|
|
|
|
GetGTKUnit(mPaperSizeUnit));
|
|
|
|
SaveNewPageSize();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::SetPaperSizeUnit(int16_t aPaperSizeUnit)
|
2008-01-21 03:47:25 +00:00
|
|
|
{
|
|
|
|
// Convert units internally. e.g. they might have set the values while we're still in mm but
|
|
|
|
// they change to inch just afterwards, expecting that their sizes are in inches.
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
gtk_paper_size_set_size(paperSize,
|
|
|
|
gtk_paper_size_get_width(paperSize, GetGTKUnit(mPaperSizeUnit)),
|
|
|
|
gtk_paper_size_get_height(paperSize, GetGTKUnit(mPaperSizeUnit)),
|
2008-01-21 03:47:25 +00:00
|
|
|
GetGTKUnit(aPaperSizeUnit));
|
|
|
|
SaveNewPageSize();
|
|
|
|
|
|
|
|
mPaperSizeUnit = aPaperSizeUnit;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetEffectivePageSize(double *aWidth, double *aHeight)
|
|
|
|
{
|
2015-11-24 22:07:21 +00:00
|
|
|
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
|
|
|
|
*aWidth = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_width(paperSize, GTK_UNIT_INCH));
|
|
|
|
*aHeight = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_height(paperSize, GTK_UNIT_INCH));
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup);
|
|
|
|
|
|
|
|
if (gtkOrient == GTK_PAGE_ORIENTATION_LANDSCAPE ||
|
|
|
|
gtkOrient == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) {
|
|
|
|
double temp = *aWidth;
|
|
|
|
*aWidth = *aHeight;
|
|
|
|
*aHeight = temp;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetupSilentPrinting()
|
|
|
|
{
|
|
|
|
// We have to get a printer here, rather than when the print settings are constructed.
|
|
|
|
// This is because when we request sync, GTK makes us wait in the *event loop* while waiting
|
|
|
|
// for the enumeration to finish. We must do this when event loop runs are expected.
|
2013-10-08 18:47:37 +00:00
|
|
|
gtk_enumerate_printers(printer_enumerator, this, nullptr, TRUE);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
// XXX If no default printer set, get the first one.
|
|
|
|
if (!GTK_IS_PRINTER(mGTKPrinter))
|
2013-10-08 18:47:37 +00:00
|
|
|
gtk_enumerate_printers(ref_printer, this, nullptr, TRUE);
|
2008-01-21 03:47:25 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-12-07 04:45:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsPrintSettingsGTK::GetPageRanges(nsTArray<int32_t> &aPages)
|
2011-12-07 04:45:06 +00:00
|
|
|
{
|
|
|
|
gint ctRanges;
|
|
|
|
GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
|
|
|
|
|
|
|
|
aPages.Clear();
|
|
|
|
|
|
|
|
if (ctRanges > 1) {
|
|
|
|
for (gint i = 0; i < ctRanges; i++) {
|
|
|
|
aPages.AppendElement(lstRanges[i].start+1);
|
|
|
|
aPages.AppendElement(lstRanges[i].end+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(lstRanges);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-11 13:10:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetResolution(int32_t *aResolution)
|
|
|
|
{
|
|
|
|
if (!gtk_print_settings_has_key(mPrintSettings, GTK_PRINT_SETTINGS_RESOLUTION))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*aResolution = gtk_print_settings_get_resolution(mPrintSettings);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetResolution(int32_t aResolution)
|
|
|
|
{
|
|
|
|
gtk_print_settings_set_resolution(mPrintSettings, aResolution);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::GetDuplex(int32_t *aDuplex)
|
|
|
|
{
|
2015-03-05 16:17:18 +00:00
|
|
|
if (!gtk_print_settings_has_key(mPrintSettings, GTK_PRINT_SETTINGS_DUPLEX)) {
|
|
|
|
*aDuplex = GTK_PRINT_DUPLEX_SIMPLEX;
|
|
|
|
} else {
|
|
|
|
*aDuplex = gtk_print_settings_get_duplex(mPrintSettings);
|
|
|
|
}
|
2013-04-11 13:10:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrintSettingsGTK::SetDuplex(int32_t aDuplex)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDuplex >= GTK_PRINT_DUPLEX_SIMPLEX &&
|
|
|
|
aDuplex <= GTK_PRINT_DUPLEX_VERTICAL,
|
|
|
|
"value is out of bounds for GtkPrintDuplex enum");
|
|
|
|
gtk_print_settings_set_duplex(mPrintSettings, static_cast<GtkPrintDuplex>(aDuplex));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|