diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2004-10-11 00:03:53 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2004-10-11 00:03:53 +0800 |
commit | ef0d06b1cca990d13d0f1e3e051248e795c4d79b (patch) | |
tree | c03d644960b6ae1863a8973a1cd1187d20a1db17 /embed/mozilla/MozillaPrivate.cpp | |
parent | 840e12a02b3e26c0697b81af8bdfdb5398017fb8 (diff) | |
download | gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar.gz gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar.bz2 gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar.lz gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar.xz gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.tar.zst gsoc2013-epiphany-ef0d06b1cca990d13d0f1e3e051248e795c4d79b.zip |
reviewed by: Christian Persch <chpe@cvs.gnome.org>
2004-10-10 Marco Pesenti Gritti <marco@gnome.org>
reviewed by: Christian Persch <chpe@cvs.gnome.org>
* data/glade/print.glade:
* embed/ephy-embed-single.c: (ephy_embed_single_get_printer_list):
* embed/ephy-embed-single.h:
* embed/mozilla/ContentHandler.cpp:
* embed/mozilla/EphyBrowser.cpp:
* embed/mozilla/EphyHeaderSniffer.cpp:
* embed/mozilla/EphyUtils.cpp:
* embed/mozilla/EphyUtils.h:
* embed/mozilla/FilePicker.cpp:
* embed/mozilla/GtkNSSClientAuthDialogs.cpp:
* embed/mozilla/GtkNSSDialogs.cpp:
* embed/mozilla/GtkNSSKeyPairDialogs.cpp:
* embed/mozilla/MozillaPrivate.cpp:
* embed/mozilla/MozillaPrivate.h:
* embed/mozilla/PrintingPromptService.cpp:
* embed/mozilla/mozilla-embed-single.cpp:
* embed/mozilla/mozilla-embed.cpp:
* embed/print-dialog.c: (ephy_print_dialog_new):
* lib/ephy-dialog.c: (set_combo_box_from_value):
Move current MozillaPrivate helpers to EphyUtils.
Use MozillaPrivate for stuff that needs mozilla
internal strings.
Support multiple printers in the print dialog.
This is actually a bug fix because on several
distributions using hardcoded Poscript/default
will simply not work at all.
Diffstat (limited to 'embed/mozilla/MozillaPrivate.cpp')
-rw-r--r-- | embed/mozilla/MozillaPrivate.cpp | 177 |
1 files changed, 37 insertions, 140 deletions
diff --git a/embed/mozilla/MozillaPrivate.cpp b/embed/mozilla/MozillaPrivate.cpp index fdece6738..74afc615e 100644 --- a/embed/mozilla/MozillaPrivate.cpp +++ b/embed/mozilla/MozillaPrivate.cpp @@ -18,159 +18,56 @@ * $Id$ */ -#include "mozilla-config.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "ephy-embed.h" -#include "mozilla-embed.h" - #include "MozillaPrivate.h" -#include <nsEmbedString.h> -#include <nsIServiceManagerUtils.h> -#include <nsIWindowWatcher.h> -#include <nsIEmbeddingSiteWindow.h> -#include <nsIWebBrowserChrome.h> -#include <gtkmozembed.h> - -GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow) -{ - if (!aDOMWindow) return nsnull; - - nsCOMPtr<nsIWindowWatcher> wwatch - (do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - NS_ENSURE_TRUE (wwatch, nsnull); - - /* this DOM window may belong to some inner frame, we need - * to get the topmost DOM window to get the embed - */ - nsCOMPtr<nsIDOMWindow> topWindow; - aDOMWindow->GetTop (getter_AddRefs (topWindow)); - if (!topWindow) return nsnull; - - nsCOMPtr<nsIWebBrowserChrome> windowChrome; - wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome)); - NS_ENSURE_TRUE (windowChrome, nsnull); - - nsCOMPtr<nsIEmbeddingSiteWindow> window (do_QueryInterface(windowChrome)); - NS_ENSURE_TRUE (window, nsnull); - - nsresult rv; - GtkWidget *mozembed; - rv = window->GetSiteWindow ((void **)&mozembed); - NS_ENSURE_SUCCESS (rv, nsnull); - - return mozembed; -} - -GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow) -{ - GtkWidget *embed = MozillaFindEmbed (aDOMWindow); - NS_ENSURE_TRUE (embed, nsnull); - - return gtk_widget_get_toplevel (GTK_WIDGET (embed)); -} +#include <nsIPrintSettingsService.h> +#include <nsIPrintOptions.h> +#include <nsIServiceManager.h> +#include <nsISimpleEnumerator.h> +#include <nsISupportsPrimitives.h> -#define MM_TO_INCH(x) (((double) x) / 25.4) +/* IMPORTANT. Put only code that use internal mozilla strings (nsAutoString for + * example) in this file. Note that you cannot use embed strings here, + * the header inclusions will conflict. + */ -NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, - nsIPrintSettings *options, - gboolean preview) +GList * +MozillaPrivate::GetPrinterList () { - const static int frame_types[] = { - nsIPrintSettings::kFramesAsIs, - nsIPrintSettings::kSelectedFrame, - nsIPrintSettings::kEachFrameSep - }; - - - switch (info->pages) - { - case 0: - options->SetPrintRange (nsIPrintSettings::kRangeAllPages); - break; - case 1: - options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange); - options->SetStartPageRange (info->from_page); - options->SetEndPageRange (info->to_page); - break; - case 2: - options->SetPrintRange (nsIPrintSettings::kRangeSelection); - break; - } - - options->SetMarginTop (MM_TO_INCH (info->top_margin)); - options->SetMarginBottom (MM_TO_INCH (info->bottom_margin)); - options->SetMarginLeft (MM_TO_INCH (info->left_margin)); - options->SetMarginRight (MM_TO_INCH (info->right_margin)); - - PRUnichar postscript[] = { 'P', 'o', 's', 't', 'S', 'c', 'r', 'i', - 'p', 't', '/', 'd', 'e', 'f', 'a', 'u', - 'l', 't', '\0' }; - options->SetPrinterName(postscript); - - nsEmbedString tmp; - - NS_CStringToUTF16 (nsEmbedCString(info->header_left_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetHeaderStrLeft (tmp.get()); + GList *printers = NULL; + nsresult rv = NS_OK; - NS_CStringToUTF16 (nsEmbedCString(info->header_center_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetHeaderStrCenter (tmp.get()); + nsCOMPtr<nsIPrintSettingsService> pss = + do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv); + NS_ENSURE_SUCCESS(rv, nsnull); - NS_CStringToUTF16 (nsEmbedCString(info->header_right_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetHeaderStrRight (tmp.get()); + nsCOMPtr<nsIPrintOptions> po = do_QueryInterface(pss, &rv); + NS_ENSURE_SUCCESS(rv, nsnull); - NS_CStringToUTF16 (nsEmbedCString(info->footer_left_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetFooterStrLeft (tmp.get()); + nsCOMPtr<nsISimpleEnumerator> avPrinters; + rv = po->AvailablePrinters(getter_AddRefs(avPrinters)); + NS_ENSURE_SUCCESS(rv, nsnull); - NS_CStringToUTF16 (nsEmbedCString(info->footer_center_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetFooterStrCenter(tmp.get()); + PRBool more = PR_FALSE; - NS_CStringToUTF16 (nsEmbedCString(info->footer_right_string), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetFooterStrRight(tmp.get()); - - NS_CStringToUTF16 (nsEmbedCString(info->file), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetToFileName (tmp.get()); - - NS_CStringToUTF16 (nsEmbedCString(info->printer), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetPrintCommand (tmp.get()); - - /** - * Work around a mozilla bug where paper size & orientation are ignored - * and the specified file is created (containing invalid postscript) - * in print preview mode if we set "print to file" to true. - * See epiphany bug #119818. - */ - if (preview) + for (avPrinters->HasMoreElements(&more); + more == PR_TRUE; + avPrinters->HasMoreElements(&more)) { - options->SetPrintToFile (PR_FALSE); - } - else - { - options->SetPrintToFile (info->print_to_file); - } + nsCOMPtr<nsISupports> i; + rv = avPrinters->GetNext(getter_AddRefs(i)); + NS_ENSURE_SUCCESS(rv, nsnull); - /* native paper size formats. Our dialog does not support custom yet */ - options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData); + nsCOMPtr<nsISupportsString> printer = do_QueryInterface(i, &rv); + NS_ENSURE_SUCCESS(rv, nsnull); - NS_CStringToUTF16 (nsEmbedCString(info->paper), - NS_CSTRING_ENCODING_UTF8, tmp); - options->SetPaperName (tmp.get()); + nsAutoString data; + rv = printer->GetData(data); + NS_ENSURE_SUCCESS(rv, nsnull); - options->SetPrintInColor (info->print_color); - options->SetOrientation (info->orientation); - options->SetPrintFrameType (frame_types[info->frame_type]); + const char *name = NS_ConvertUCS2toUTF8 (data).get(); + printers = g_list_prepend (printers, g_strdup (name)); + } - return NS_OK; + return g_list_reverse (printers); } |