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 | |
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')
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 6 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 3 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 1 | ||||
-rw-r--r-- | embed/mozilla/EphyUtils.cpp | 142 | ||||
-rw-r--r-- | embed/mozilla/EphyUtils.h | 18 | ||||
-rw-r--r-- | embed/mozilla/FilePicker.cpp | 4 | ||||
-rw-r--r-- | embed/mozilla/GtkNSSClientAuthDialogs.cpp | 4 | ||||
-rw-r--r-- | embed/mozilla/GtkNSSDialogs.cpp | 18 | ||||
-rw-r--r-- | embed/mozilla/GtkNSSKeyPairDialogs.cpp | 4 | ||||
-rw-r--r-- | embed/mozilla/MozillaPrivate.cpp | 177 | ||||
-rw-r--r-- | embed/mozilla/MozillaPrivate.h | 16 | ||||
-rw-r--r-- | embed/mozilla/PrintingPromptService.cpp | 8 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 9 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 1 |
14 files changed, 230 insertions, 181 deletions
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 422597d03..48ba7951e 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -54,8 +54,8 @@ #include "eel-gconf-extensions.h" #include "ContentHandler.h" -#include "MozillaPrivate.h" #include "MozDownload.h" +#include "EphyUtils.h" class GContentHandler; @@ -143,7 +143,7 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( } nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (aWindowContext); - GtkWidget *parentWindow = GTK_WIDGET (MozillaFindGtkParent (parentDOMWindow)); + GtkWidget *parentWindow = GTK_WIDGET (EphyUtils::FindGtkParent (parentDOMWindow)); dialog = ephy_file_chooser_new (_("Save"), parentWindow, GTK_FILE_CHOOSER_ACTION_SAVE, @@ -267,7 +267,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction () int response; nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (mContext); - GtkWindow *parentWindow = GTK_WINDOW (MozillaFindGtkParent(parentDOMWindow)); + GtkWindow *parentWindow = GTK_WINDOW (EphyUtils::FindGtkParent(parentDOMWindow)); action_label = (mAction == CONTENT_ACTION_OPEN) || (mAction == CONTENT_ACTION_OPEN_TMP) ? diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 655c3b110..040b7615f 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -26,7 +26,6 @@ #include "EphyBrowser.h" #include "EphyUtils.h" -#include "MozillaPrivate.h" #include "ephy-embed.h" #include "ephy-string.h" #include "ephy-debug.h" @@ -330,7 +329,7 @@ nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode) print->GetGlobalPrintSettings (getter_AddRefs(settings)); info = ephy_print_get_print_info (); - MozillaCollatePrintSettings (info, settings, TRUE); + EphyUtils::CollatePrintSettings (info, settings, TRUE); ephy_print_info_free (info); rv = print->PrintPreview (nsnull, mDOMWindow, nsnull); diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 955d8ed00..95636f98d 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -45,7 +45,6 @@ #include "config.h" #endif -#include "MozillaPrivate.h" #include "MozDownload.h" #include "EphyHeaderSniffer.h" diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp index 9b271abaf..c5e0bf666 100644 --- a/embed/mozilla/EphyUtils.cpp +++ b/embed/mozilla/EphyUtils.cpp @@ -25,9 +25,15 @@ #endif #include "EphyUtils.h" +#include "ephy-embed-shell.h" +#include "ephy-embed-single.h" #include <nsIServiceManager.h> #include <nsEmbedString.h> +#include <nsIWindowWatcher.h> +#include <nsIEmbeddingSiteWindow.h> +#include <nsIWebBrowserChrome.h> +#include <gtkmozembed.h> nsresult EphyUtils::GetIOService (nsIIOService **ioService) @@ -64,3 +70,139 @@ nsresult EphyUtils::NewURI (nsIURI **result, const nsACString &spec) return rv; } + +GtkWidget * +EphyUtils::FindEmbed (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 * +EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow) +{ + GtkWidget *embed = FindEmbed (aDOMWindow); + NS_ENSURE_TRUE (embed, nsnull); + + return gtk_widget_get_toplevel (GTK_WIDGET (embed)); +} + +#define MM_TO_INCH(x) (((double) x) / 25.4) + +nsresult +EphyUtils::CollatePrintSettings (const EmbedPrintInfo *info, + nsIPrintSettings *options, + gboolean preview) +{ + 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)); + + nsEmbedString tmp; + + NS_CStringToUTF16 (nsEmbedCString(info->header_left_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrLeft (tmp.get()); + + NS_CStringToUTF16 (nsEmbedCString(info->header_center_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrCenter (tmp.get()); + + NS_CStringToUTF16 (nsEmbedCString(info->header_right_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrRight (tmp.get()); + + NS_CStringToUTF16 (nsEmbedCString(info->footer_left_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetFooterStrLeft (tmp.get()); + + NS_CStringToUTF16 (nsEmbedCString(info->footer_center_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetFooterStrCenter(tmp.get()); + + 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->SetPrinterName (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) + { + options->SetPrintToFile (PR_FALSE); + } + else + { + options->SetPrintToFile (info->print_to_file); + } + + /* native paper size formats. Our dialog does not support custom yet */ + options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData); + + NS_CStringToUTF16 (nsEmbedCString(info->paper), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetPaperName (tmp.get()); + + options->SetPrintInColor (info->print_color); + options->SetOrientation (info->orientation); + options->SetPrintFrameType (frame_types[info->frame_type]); + + return NS_OK; +} diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h index 0fcbe488a..2f81e0b4d 100644 --- a/embed/mozilla/EphyUtils.h +++ b/embed/mozilla/EphyUtils.h @@ -22,14 +22,26 @@ #include <nsIIOService.h> #include <nsIURI.h> +#include <nsIDOMWindow.h> +#include <nsIPrintSettings.h> + +#include "print-dialog.h" namespace EphyUtils { - nsresult GetIOService (nsIIOService **ioService); + nsresult GetIOService (nsIIOService **ioService); + + nsresult NewURI (nsIURI **result, const nsAString &spec); + + nsresult NewURI (nsIURI **result, const nsACString &spec); + + GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow); - nsresult NewURI (nsIURI **result, const nsAString &spec); + GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow); - nsresult NewURI (nsIURI **result, const nsACString &spec); + nsresult CollatePrintSettings (const EmbedPrintInfo *info, + nsIPrintSettings *settings, + gboolean preview); } #endif diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index a0e90f781..2a4c39ce5 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -26,7 +26,7 @@ #endif #include "FilePicker.h" -#include "MozillaPrivate.h" +#include "EphyUtils.h" #include <nsCOMPtr.h> #include <nsEmbedString.h> @@ -82,7 +82,7 @@ NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *t { LOG ("GFilePicker::Init") - GtkWidget *gtkparent = MozillaFindGtkParent (parent); + GtkWidget *gtkparent = EphyUtils::FindGtkParent (parent); #if defined(MOZ_NSIFILEPICKER_NSASTRING_) NS_ENSURE_TRUE (gtkparent, NS_ERROR_FAILURE); #endif diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp index 28143b2e8..ec4481c12 100644 --- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp +++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_MOZILLA_PSM -#include "MozillaPrivate.h" +#include "EphyUtils.h" #include <nsIServiceManager.h> #include <nsIInterfaceRequestor.h> @@ -146,7 +146,7 @@ GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, PRUint32 i; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp index b6b2f05b0..f2031714c 100644 --- a/embed/mozilla/GtkNSSDialogs.cpp +++ b/embed/mozilla/GtkNSSDialogs.cpp @@ -34,7 +34,7 @@ #ifdef HAVE_MOZILLA_PSM -#include "MozillaPrivate.h" +#include "EphyUtils.h" #include <nsCOMPtr.h> #include <nsMemory.h> @@ -209,7 +209,7 @@ display_cert_warning_box (nsIInterfaceRequestor *ctx, int res; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); g_return_val_if_fail (markup_text, GTK_RESPONSE_CANCEL); g_return_val_if_fail (!checkbox_text || checkbox_value, GTK_RESPONSE_CANCEL); @@ -480,7 +480,7 @@ GtkNSSDialogs::NotifyCrlNextupdate (nsIInterfaceRequestor *ctx, char *ttCommonName, *ttTargetUrl, *msg, *primary, *secondary; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), @@ -545,7 +545,7 @@ GtkNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, char *ttCommonName, *msg, *tertiary; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), @@ -644,7 +644,7 @@ GtkNSSDialogs::NotifyCACertExists (nsIInterfaceRequestor *ctx) char * msg; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), @@ -766,7 +766,7 @@ GtkNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, char *msg; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", @@ -879,7 +879,7 @@ GtkNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, char *msg; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), @@ -963,7 +963,7 @@ GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl char *msg; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), @@ -1311,7 +1311,7 @@ GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, &dialog, NULL, NULL); nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(gparent)); gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp index 2ac454182..b0ff1cf0b 100644 --- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp +++ b/embed/mozilla/GtkNSSKeyPairDialogs.cpp @@ -43,7 +43,7 @@ #ifdef HAVE_MOZILLA_PSM -#include "MozillaPrivate.h" +#include "EphyUtils.h" #include <nsIServiceManager.h> #include <nsIInterfaceRequestor.h> @@ -169,7 +169,7 @@ GtkNSSKeyPairDialogs::DisplayGeneratingKeypairInfo (nsIInterfaceRequestor *ctx, nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = MozillaFindGtkParent (parent); + GtkWidget *gparent = EphyUtils::FindGtkParent (parent); dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent), GTK_DIALOG_NO_SEPARATOR, NULL); 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); } diff --git a/embed/mozilla/MozillaPrivate.h b/embed/mozilla/MozillaPrivate.h index 83966097a..fb0fc83d1 100644 --- a/embed/mozilla/MozillaPrivate.h +++ b/embed/mozilla/MozillaPrivate.h @@ -17,15 +17,9 @@ * */ -#include <nsIPrintSettings.h> -#include <nsIDOMWindow.h> +#include <glib.h> -#include "print-dialog.h" - -GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow); - -GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow); - -NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, - nsIPrintSettings *settings, - gboolean preview); +namespace MozillaPrivate +{ + GList *GetPrinterList (); +} diff --git a/embed/mozilla/PrintingPromptService.cpp b/embed/mozilla/PrintingPromptService.cpp index 3eb4886ec..05138e86d 100644 --- a/embed/mozilla/PrintingPromptService.cpp +++ b/embed/mozilla/PrintingPromptService.cpp @@ -30,7 +30,7 @@ #include "print-dialog.h" #include "ephy-embed.h" #include "ephy-command-manager.h" -#include "MozillaPrivate.h" +#include "EphyUtils.h" #include "PrintingPromptService.h" #include "eel-gconf-extensions.h" #include "ephy-prefs.h" @@ -63,13 +63,13 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW return NS_ERROR_ABORT; } - EphyEmbed *embed = EPHY_EMBED (MozillaFindEmbed (parent)); + EphyEmbed *embed = EPHY_EMBED (EphyUtils::FindEmbed (parent)); NS_ENSURE_TRUE (embed, NS_ERROR_FAILURE); if (!(eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP) || eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_COMMAND_LINE))) { - GtkWidget *gtkParent = MozillaFindGtkParent(parent); + GtkWidget *gtkParent = EphyUtils::FindGtkParent(parent); NS_ENSURE_TRUE (gtkParent, NS_ERROR_FAILURE); dialog = ephy_print_dialog_new (gtkParent, embed); @@ -96,7 +96,7 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW info->pages = 0; } - MozillaCollatePrintSettings (info, printSettings, FALSE); + EphyUtils::CollatePrintSettings (info, printSettings, FALSE); ephy_print_info_free (info); diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 94f3123e3..756c3c4b5 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -627,6 +627,12 @@ impl_get_offline_mode (EphyEmbedSingle *shell) } static GList * +impl_get_printer_list (EphyEmbedSingle *shell) +{ + return MozillaPrivate::GetPrinterList (); +} + +static GList * impl_get_font_list (EphyEmbedSingle *shell, const char *langGroup) { @@ -958,7 +964,7 @@ impl_open_window (EphyEmbedSingle *single, wWatch->OpenWindow (domWindow, address, name, features, nsnull, getter_AddRefs (newWindow)); - return MozillaFindEmbed (newWindow); + return EphyUtils::FindEmbed (newWindow); } static void @@ -983,6 +989,7 @@ ephy_embed_single_iface_init (EphyEmbedSingleIface *iface) iface->get_offline_mode = impl_get_offline_mode; iface->get_font_list = impl_get_font_list; iface->open_window = impl_open_window; + iface->get_printer_list = impl_get_printer_list; } static void diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index 7d98478cf..bf71f361e 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -32,7 +32,6 @@ #include "ephy-string.h" #include "ephy-debug.h" -#include "MozillaPrivate.h" #include "EphyBrowser.h" #include "EventContext.h" #include "EphyUtils.h" |