/* -*- 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/. */
// To be convenient, prefill the textbox with the existing value, if any, and // select it all so they can easily both edit it and type in a new one. constchar* current_text =
(constchar*)g_object_get_data(G_OBJECT(changed_box), "custom-text"); if (current_text) {
gtk_entry_set_text(GTK_ENTRY(custom_entry), current_text);
gtk_editable_select_region(GTK_EDITABLE(custom_entry), 0, -1);
}
gtk_entry_set_activates_default(GTK_ENTRY(custom_entry), TRUE);
/* Code to copy between GTK and NS print settings structures. * In the following, * "Import" means to copy from NS to GTK * "Export" means to copy from GTK to NS
*/ void ExportHeaderFooter(nsIPrintSettings* aNS);
};
nsPrintDialogWidgetGTK::nsPrintDialogWidgetGTK(nsPIDOMWindowOuter* aParent, bool aHaveSelection,
nsIPrintSettings* aSettings) {
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aParent);
NS_ASSERTION(widget, "Need a widget for dialog to be modal.");
GtkWindow* gtkParent = get_gtk_window_for_nsiwidget(widget);
NS_ASSERTION(gtkParent, "Need a GTK window for dialog to be modal.");
// The vast majority of magic numbers in this widget construction are padding. // e.g. for the set_border_width below, 12px matches that of just about every // other window.
GtkWidget* custom_options_tab = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(custom_options_tab), 12);
GtkWidget* tab_label =
gtk_label_new(GetUTF8FromBundle("optionsTabLabelGTK").get());
// GTK+2.18 and above allow us to add a "Selection" option to the main // settings screen, rather than adding an option on a custom tab like we must // do on older versions. if (gtk_major_version > 2 ||
(gtk_major_version == 2 && gtk_minor_version >= 18)) {
useNativeSelection = true;
g_object_set(dialog, "support-selection", TRUE, "has-selection",
aHaveSelection, "embed-page-setup", TRUE, nullptr);
} else {
useNativeSelection = false;
selection_only_toggle = gtk_check_button_new_with_mnemonic(
GetUTF8FromBundle("selectionOnly").get());
gtk_widget_set_sensitive(selection_only_toggle, aHaveSelection);
gtk_box_pack_start(GTK_BOX(check_buttons_container), selection_only_toggle, FALSE, FALSE, 0);
}
for (unsignedint i = 0; i < std::size(header_dropdown); i++) {
header_dropdown[i] =
ConstructHeaderFooterDropdown(header_footer_str[i].get()); // Those 4 magic numbers in the middle provide the position in the table. // The last two numbers mean 2 px padding on every side.
gtk_table_attach(GTK_TABLE(header_footer_table), header_dropdown[i], i,
(i + 1), 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 2,
2);
}
constchar labelKeys[][7] = {"left", "center", "right"}; for (unsignedint i = 0; i < std::size(labelKeys); i++) {
gtk_table_attach(GTK_TABLE(header_footer_table),
gtk_label_new(GetUTF8FromBundle(labelKeys[i]).get()), i,
(i + 1), 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 2,
2);
}
nsresult nsPrintDialogWidgetGTK::ImportSettings(nsIPrintSettings* aNSSettings) {
MOZ_ASSERT(aNSSettings, "aSettings must not be null");
NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings)); if (!aNSSettingsGTK) return NS_ERROR_FAILURE;
// Temporarily set the pages-per-sheet on the GtkPrintSettings:
int32_t pagesPerSide = 1;
aNSSettings->GetNumPagesPerSheet(&pagesPerSide);
gtk_print_settings_set_number_up(settings, pagesPerSide);
nsresult nsPrintDialogWidgetGTK::ExportSettings(nsIPrintSettings* aNSSettings) {
MOZ_ASSERT(aNSSettings, "aSettings must not be null");
NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
// Print-to-file is true by default. This must be turned off or else // printing won't occur! (We manually copy the spool file when this flag is // set, because we love our embedders) Even if it is print-to-file in GTK's // case, GTK does The Right Thing when we send the job.
aNSSettings->SetOutputDestination(
nsIPrintSettings::kOutputDestinationPrinter);
for (unsignedint i = 0; i < std::size(hf_options); i++) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(dropdown), nullptr,
GetUTF8FromBundle(hf_options[i]).get());
}
NS_IMETHODIMP
nsPrintDialogServiceGTK::ShowPrintDialog(mozIDOMWindowProxy* aParent, bool aHaveSelection,
nsIPrintSettings* aSettings) {
MOZ_ASSERT(aParent, "aParent must not be null");
MOZ_ASSERT(aSettings, "aSettings must not be null");
NS_IMETHODIMP
nsPrintDialogServiceGTK::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
nsIPrintSettings* aNSSettings) {
MOZ_ASSERT(aParent, "aParent must not be null");
MOZ_ASSERT(aNSSettings, "aSettings must not be null");
NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
nsCOMPtr<nsIWidget> widget =
WidgetUtils::DOMWindowToWidget(nsPIDOMWindowOuter::From(aParent));
NS_ASSERTION(widget, "Need a widget for dialog to be modal.");
GtkWindow* gtkParent = get_gtk_window_for_nsiwidget(widget);
NS_ASSERTION(gtkParent, "Need a GTK window for dialog to be modal.");
nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings)); if (!aNSSettingsGTK) return NS_ERROR_FAILURE;
// We need to init the prefs here because aNSSettings in its current form is a // dummy in both uses of the word
nsCOMPtr<nsIPrintSettingsService> psService =
do_GetService("@mozilla.org/gfx/printsettings-service;1"); if (psService) {
nsString printName;
aNSSettings->GetPrinterName(printName); if (printName.IsVoid()) {
psService->GetLastUsedPrinterName(printName);
aNSSettings->SetPrinterName(printName);
}
psService->InitPrintSettingsFromPrefs(aNSSettings, true,
nsIPrintSettings::kInitSaveAll);
}
// Frustratingly, gtk_print_run_page_setup_dialog doesn't tell us whether // the user cancelled or confirmed the dialog! So to avoid needlessly // refreshing the preview when Page Setup was cancelled, we compare the // serializations of old and new settings; if they're the same, bail out.
GtkPrintSettings* gtkSettings = aNSSettingsGTK->GetGtkPrintSettings();
GtkPageSetup* oldPageSetup = aNSSettingsGTK->GetGtkPageSetup();
GKeyFile* oldKeyFile = g_key_file_new();
gtk_page_setup_to_key_file(oldPageSetup, oldKeyFile, nullptr);
gsize oldLength;
gchar* oldData = g_key_file_to_data(oldKeyFile, &oldLength, nullptr);
g_key_file_free(oldKeyFile);
// Now newPageSetup has a refcount of 2 (SetGtkPageSetup will addref), put it // to 1 so if this gets replaced we don't leak.
g_object_unref(newPageSetup);
if (psService)
psService->MaybeSavePrintSettingsToPrefs(
aNSSettings, nsIPrintSettings::kInitSaveOrientation |
nsIPrintSettings::kInitSavePaperSize |
nsIPrintSettings::kInitSaveUnwriteableMargins);
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 und die Messung sind noch experimentell.