/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
// These constants are the the strings that GTK expects as key-value pairs for // setting CUPS duplex modes. These are not universal to all CUPS systems, which // is why they are local to this file. static constexpr gchar kCupsDuplex[] = "cups-Duplex"; static constexpr gchar kCupsDuplexNone[] = "None"; static constexpr gchar kCupsDuplexNoTumble[] = "DuplexNoTumble"; static constexpr gchar kCupsDuplexTumble[] = "DuplexTumble";
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);
}
/** ---------------------------------------------------
*/
nsPrintSettingsGTK::nsPrintSettingsGTK()
: mPageSetup(nullptr), mPrintSettings(nullptr), mGTKPrinter(nullptr) { // 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();
GtkPageSetup* pageSetup = gtk_page_setup_new();
SetGtkPageSetup(pageSetup);
g_object_unref(pageSetup);
if (mPageSetup) g_object_unref(mPageSetup);
mPageSetup = gtk_page_setup_copy(rhs.mPageSetup); // NOTE: No need to re-initialize mUnwriteableMargin here (even // though mPageSetup is changing). It'll be copied correctly by // nsPrintSettings::operator=.
if (mPrintSettings) g_object_unref(mPrintSettings);
mPrintSettings = gtk_print_settings_copy(rhs.mPrintSettings);
if (mGTKPrinter) g_object_unref(mGTKPrinter);
if (rhs.mGTKPrinter) {
g_object_ref(rhs.mGTKPrinter);
}
mGTKPrinter = rhs.mGTKPrinter;
// 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);
}
SaveNewPageSize();
}
/** ---------------------------------------------------
*/ void nsPrintSettingsGTK::SetGtkPrintSettings(GtkPrintSettings* aPrintSettings) { if (mPrintSettings) g_object_unref(mPrintSettings);
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();
}
}
/** ---------------------------------------------------
*/ void nsPrintSettingsGTK::SetGtkPrinter(GtkPrinter* aPrinter) { if (mGTKPrinter) g_object_unref(mGTKPrinter);
NS_IMETHODIMP
nsPrintSettingsGTK::GetPrinterName(nsAString& aPrinter) { constchar* gtkPrintName = gtk_print_settings_get_printer(mPrintSettings); if (!gtkPrintName) { if (GTK_IS_PRINTER(mGTKPrinter)) {
gtkPrintName = gtk_printer_get_name(mGTKPrinter);
} else { // This mimics what nsPrintSettingsImpl does when we try to Get before we // Set
aPrinter.Truncate(); return NS_OK;
}
}
CopyUTF8toUTF16(mozilla::MakeStringSpan(gtkPrintName), aPrinter); return NS_OK;
}
if (StringBeginsWith(gtkPrinter, "CUPS/"_ns)) { // Strip off "CUPS/"; GTK might recognize the rest
gtkPrinter.Cut(0, strlen("CUPS/"));
}
// 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. constchar* oldPrinterName = gtk_print_settings_get_printer(mPrintSettings); if (!oldPrinterName || !gtkPrinter.Equals(oldPrinterName)) {
mIsInitedFromPrinter = false;
mIsInitedFromPrefs = false;
gtk_print_settings_set_printer(mPrintSettings, gtkPrinter.get());
}
// Convert these Gecko names to GTK names // XXX (jfkthame): is this still relevant? if (gtkPaperName.EqualsIgnoreCase("letter"))
gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LETTER); elseif (gtkPaperName.EqualsIgnoreCase("legal"))
gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LEGAL);
// 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());
GtkPaperSize* customPaperSize = gtk_paper_size_new_custom(
gtkPaperName.get(), gtk_paper_size_get_display_name(paperSize), width,
height, GTK_UNIT_INCH);
gtk_paper_size_free(paperSize);
/** * 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
nsPrintSettingsGTK::SetUnwriteableMarginInTwips(
nsIntMargin& aUnwriteableMargin) {
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::SetPaperSizeUnit(int16_t aPaperSizeUnit) { // 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.
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)),
GetGTKUnit(aPaperSizeUnit));
SaveNewPageSize();
if (!gtk_print_settings_has_key(mPrintSettings, GTK_PRINT_SETTINGS_DUPLEX)) { return NS_OK;
}
switch (gtk_print_settings_get_duplex(mPrintSettings)) { case GTK_PRINT_DUPLEX_SIMPLEX:
*aDuplex = kDuplexNone; break; case GTK_PRINT_DUPLEX_HORIZONTAL:
*aDuplex = kDuplexFlipOnLongEdge; break; case GTK_PRINT_DUPLEX_VERTICAL:
*aDuplex = kDuplexFlipOnShortEdge; break;
}
return NS_OK;
}
NS_IMETHODIMP
nsPrintSettingsGTK::SetDuplex(int32_t aDuplex) {
uint32_t duplex = static_cast<uint32_t>(aDuplex);
MOZ_ASSERT(duplex <= kDuplexFlipOnShortEdge, "value is out of bounds for duplex enum");
// We want to set the GTK CUPS Duplex setting in addition to calling // gtk_print_settings_set_duplex(). Some systems may look for one, or the // other, so it is best to set them both consistently. switch (duplex) { case kDuplexNone:
gtk_print_settings_set(mPrintSettings, kCupsDuplex, kCupsDuplexNone);
gtk_print_settings_set_duplex(mPrintSettings, GTK_PRINT_DUPLEX_SIMPLEX); break; case kDuplexFlipOnLongEdge:
gtk_print_settings_set(mPrintSettings, kCupsDuplex, kCupsDuplexNoTumble);
gtk_print_settings_set_duplex(mPrintSettings,
GTK_PRINT_DUPLEX_HORIZONTAL); break; case kDuplexFlipOnShortEdge:
gtk_print_settings_set(mPrintSettings, kCupsDuplex, kCupsDuplexTumble);
gtk_print_settings_set_duplex(mPrintSettings, GTK_PRINT_DUPLEX_VERTICAL); break;
}
return NS_OK;
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.